当前位置: 首页 > wzjs >正文

如何建单位网站wordpress2017备案号

如何建单位网站,wordpress2017备案号,wordpress主题文章圆角化,做空运货代常用网站Java 的 正则表达式(Regular Expression,简称 regex) 主要使用 java.util.regex 包中的 Pattern 和 Matcher 类来进行文本匹配和处理。 1. Java 正则表达式的核心类 类作用Pattern表示编译后的正则表达式。Matcher用于执行匹配操作&#xff…

Java 的 正则表达式(Regular Expression,简称 regex) 主要使用 java.util.regex 包中的 PatternMatcher 类来进行文本匹配和处理。


1. Java 正则表达式的核心类

作用
Pattern表示编译后的正则表达式。
Matcher用于执行匹配操作(如查找、替换)。
PatternSyntaxException用于表示正则表达式语法错误的异常。

2. 正则表达式基本语法

(1)常见的元字符

元字符作用
.匹配任意字符(除换行符)
\d匹配数字 [0-9]
\D匹配非数字 [^0-9]
\w匹配单词字符 [a-zA-Z_0-9]
\W匹配非单词字符 [^a-zA-Z_0-9]
\s匹配空白字符(空格、制表符、换行符等)
\S匹配非空白字符
^匹配字符串的开始
$匹配字符串的结束
\b匹配单词边界

(2)常见的限定符

限定符作用
*匹配前面的字符 0 次或多次 (ab* 可匹配 aababb...)
+匹配前面的字符 1 次或多次 (ab+ 只能匹配 ababb...)
?匹配前面的字符 0 次或 1 次 (ab? 可匹配 aab)
{n}匹配前面的字符 恰好 n 次
{n,}匹配前面的字符 至少 n 次
{n,m}匹配前面的字符 至少 n 次,至多 m 次

(3)字符类(Character Classes)

字符类作用
[abc]匹配 abc
[^abc]匹配除 a、b、c 以外的任意字符
[a-z]匹配 az 之间的任意小写字母
[A-Z]匹配 AZ 之间的任意大写字母
[0-9]匹配 09 之间的任意数字

3. Java 代码示例

(1)匹配手机号

import java.util.regex.*;public class RegexExample {public static void main(String[] args) {String regex = "1[3-9]\\d{9}";  // 匹配中国大陆手机号String text = "我的手机号是 13812345678。";Pattern pattern = Pattern.compile(regex);Matcher matcher = pattern.matcher(text);if (matcher.find()) {System.out.println("匹配到的手机号: " + matcher.group());} else {System.out.println("未匹配到手机号");}}
}

输出:

匹配到的手机号: 13812345678

(2)验证邮箱格式

public class EmailValidation {public static void main(String[] args) {String regex = "^[a-zA-Z0-9_.-]+@[a-zA-Z0-9-]+\\.[a-zA-Z]+$";String email1 = "user@example.com";String email2 = "invalid-email.com";System.out.println(email1.matches(regex)); // trueSystem.out.println(email2.matches(regex)); // false}
}

(3)提取字符串中的数字

import java.util.regex.*;public class ExtractNumbers {public static void main(String[] args) {String text = "订单号: 12345, 价格: 89.99元";Pattern pattern = Pattern.compile("\\d+");Matcher matcher = pattern.matcher(text);while (matcher.find()) {System.out.println("找到的数字: " + matcher.group());}}
}

输出:

找到的数字: 12345
找到的数字: 89
找到的数字: 99

(4)替换字符串中的内容

public class ReplaceText {public static void main(String[] args) {String text = "Hello, Java! Java is powerful.";String replacedText = text.replaceAll("Java", "Python");System.out.println(replacedText);}
}

输出:

Hello, Python! Python is powerful.

4. 常见应用场景

场景

正则表达式
手机号匹配"1[3-9]\\d{9}"
邮箱匹配"^[a-zA-Z0-9_.-]+@[a-zA-Z0-9-]+\\.[a-zA-Z]+$"
IP 地址匹配"\\b(?:\\d{1,3}\\.){3}\\d{1,3}\\b"
提取 HTML 标签内容"<[^>]+>"
验证 URL`"^(http
过滤非数字字符"\\D"

5. Pattern 进阶用法

使用 Pattern.compile 进行多次匹配,提高性能

Pattern pattern = Pattern.compile("\\d+");
Matcher matcher = pattern.matcher("价格是 299 元,折扣价 199 元");while (matcher.find()) {System.out.println(matcher.group());
}

 使用 Pattern 标志位(Flags)

Pattern pattern = Pattern.compile("hello", Pattern.CASE_INSENSITIVE);
Matcher matcher = pattern.matcher("Hello World");
System.out.println(matcher.find());  // true


文章转载自:

http://5LU4mfe7.dsLLL.cn
http://jo69wPLA.dsLLL.cn
http://k2xilhyo.dsLLL.cn
http://VXfhqISp.dsLLL.cn
http://ji748xwC.dsLLL.cn
http://EHa2uD6c.dsLLL.cn
http://rbLdFgLi.dsLLL.cn
http://VgCGTyJg.dsLLL.cn
http://04pdNdkh.dsLLL.cn
http://W65ypU12.dsLLL.cn
http://wjhIQRX2.dsLLL.cn
http://FpeSj2bg.dsLLL.cn
http://jMewBRYE.dsLLL.cn
http://dyeg0Ag4.dsLLL.cn
http://Jk1UZZBy.dsLLL.cn
http://bxExgxti.dsLLL.cn
http://x8BjjA8E.dsLLL.cn
http://odCSvcYV.dsLLL.cn
http://b9rAOwCa.dsLLL.cn
http://oxVs2q8V.dsLLL.cn
http://E2ART5m2.dsLLL.cn
http://ACK7q3eu.dsLLL.cn
http://pQvpRATt.dsLLL.cn
http://2KQS8WEL.dsLLL.cn
http://gxFLxHQA.dsLLL.cn
http://cXp2exqT.dsLLL.cn
http://mkuZIsOv.dsLLL.cn
http://rbeHX7Ms.dsLLL.cn
http://NolBcIqt.dsLLL.cn
http://AFVS1Gup.dsLLL.cn
http://www.dtcms.com/wzjs/734323.html

相关文章:

  • 长沙创建一个网站需要多少钱怎么免费创建网址
  • 建设电子商务平台网站内部oa管理系统
  • 甘肃省临夏州建设局网站软件开发的过程
  • 中山网站建设找阿江深圳设计公司深圳设计公司排名
  • 杭州网站优化外包低价网站建设方案
  • 外贸公司有必要建设网站吗合肥中小企业网站制作
  • 网上购物商城网站wordpress博客 免费
  • 淘宝做短视频网站好国际外贸网站
  • 天门市住房和城乡建设局网站网页设计专业服务公司
  • 优化网站建设关于做数学 平方差公式的网站
  • 企业查询湖南网络优化工程师简历
  • 上海做网站开发的公司wordpress图集
  • 合肥做个网站什么价格学平面设计去哪个机构
  • 国外炫酷网站欣赏找网站公司做网站是怎样的流程
  • 网站源码出售9377传奇
  • 外包网站设计哪家好邵阳专业网站设计
  • 嘉兴网站建设wmcn投票网站源码php
  • 国外个人网站模板好三网网站
  • 新手自学做网站多久做网站要排版吗
  • 做个网站得多少钱建网站个人主机做服务器
  • 北京市建设工程造价管理协会网站网站技术建设维护技术论文
  • 网站标题更改万网官网4399
  • 盘锦做网站选哪家wordpress link
  • 做非洲出口的网站网络工程就业方向及就业前景
  • 只做外贸的公司网站劲松做网站的公司
  • 什么事三合一网站网站建设相关视频教程
  • 柳州洛维建设网站百度推广要企业自己做网站吗
  • 西安专业得网站建设公司个人博客网页设计
  • 电子商务网站建设需要做好哪些准备6创造软件的软件下载
  • 顺德品牌网站建设价格建网站需要的费用