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

专业网站建设价格南京响应式网站建设

专业网站建设价格,南京响应式网站建设,文交所网站建设方案,那些免费网站可以做国外贸易文章目录 快速入门匹配中文或数字或大小写字母(一个或多个) 正则表达式底层实现(重要)mather.find() 完成的任务mather.group(0) 分析 正则表达式基本语法元字符转义字符区分大小写限定字符选择匹配符特殊字符字符匹配符定位符 分组、捕获和反向引用捕获特别分组反向引用经典结…

文章目录

  • 快速入门
    • 匹配中文或数字或大小写字母(一个或多个)
  • 正则表达式底层实现(重要)
    • mather.find() 完成的任务
    • mather.group(0) 分析
  • 正则表达式基本语法
    • 元字符
      • 转义字符
      • 区分大小写
      • 限定字符
      • 选择匹配符
      • 特殊字符
      • 字符匹配符
      • 定位符
    • 分组、捕获和反向引用
      • 捕获
      • 特别分组
      • 反向引用
        • 经典结巴程序
  • 三个常用类
    • Pattern
      • 常用方法
        • matches 整体匹配
    • Matcher
      • 常用方法
    • PatternSyntaxException
  • 应用实例
    • 匹配汉字、邮政编码、qq号码、手机号
    • 匹配url
    • 对url进行解析
  • String中使用正则表达式
    • 替换
    • 验证手机号
    • 分割匹配
    • 验证是不是整数或者小数
    • 分割匹配
    • 验证是不是整数或者小数

快速入门

简单的说:正则表达式是对字符串执行模式匹配的技术。

正则表达式:regular expression=>RegExp

匹配中文或数字或大小写字母(一个或多个)

String content = "abc12ABC34231esdfsABCdsadd想问ABC下我下午";
// 创建Pattern对象,模式对象
Pattern pattern = Pattern.compile("([\\u4e00-\\u9fff]+)|([0-9]+)|([a-zA-Z]+)");
// 创建匹配器对象
//理解:就是matcher匹配器按照 pattern(模式/样式),到content文本中去匹配
// 找到就返回true,否则就返回false
Matcher matcher = pattern.matcher(content);
while (matcher.find()) {// 匹配内容、文本,放到 m.group(0)System.out.println(matcher.group(0));
}

在这里插入图片描述

输出

在这里插入图片描述

正则表达式底层实现(重要)

mather.find() 完成的任务

在这里插入图片描述

考虑分组

在这里插入图片描述

在这里插入图片描述

mather.group(0) 分析

在这里插入图片描述

1.根据groups[0]=0和groups[1]=4的记录的位置,从content开始截取子字符串返回
就是[0,4) 包含0但是不包含索引为4的位置

如果再次指向find方法,仍然按上面分析来执行

在这里插入图片描述

//1小结
//1.如果正则表达式有()即分组
//2.取出匹配的字符串规则如下
//3. group(0)表示匹配到的子字符串
//4. group(1)表示匹配到的子字符串的第1组字串
//5. group(2)表示匹配到的子字符串的第2组字串
//16. … 但是分组的数不能越界

在这里插入图片描述

正则表达式基本语法

元字符

转义字符

在Java的正则表达式中,两个\代表其他语
言中的一个\

在这里插入图片描述

区分大小写

java正则表达式默认是区分字母大小写的,如何实现不区分大小写

在这里插入图片描述

限定字符

在这里插入图片描述

在这里插入图片描述

细节:java匹配默认贪婪匹配,即尽可能匹配多的

选择匹配符

在这里插入图片描述

特殊字符

字符匹配符

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

定位符

在这里插入图片描述

分组、捕获和反向引用

1.分组
我们可以用圆括号组成一个比较复杂的匹配模式,那么一个圆括号的部分我们可
以看作是一个子表达式/一个分组。
2.捕获
把正则表达式中子表达式/分组匹配的内容,保存到内存中以数字编号或显式命名
的组里,方便后面引用,从左向右,以分组的左括号为标志,第一个出现的分组
的组号为1,第二个为2,以此类推。组0代表的是整个正则式
3.反向引用
圆括号的内容被捕获后,可以在这个括号后被使用,从而写出一个比较实用的匹
配模式,这个我们称为反向引用,这种引用既可以是在正则表达式内部,也可以是
在正则表达式外部,内部反向引用分组号,外部反向引用$分组号

捕获

在这里插入图片描述

特别分组

在这里插入图片描述

反向引用

在这里插入图片描述

在这里插入图片描述

经典结巴程序
String content = "我...我要...学学学学...编程java";
// 去掉所有的.
Pattern pattern = Pattern.compile("\\.");
Matcher matcher = pattern.matcher(content);
content = matcher.replaceAll("");
System.out.println(content);//String regExp = "([\\u4e00-\\u9fff])\\1+([\\u4e00-\\u9fff])\\2?([\\u4e00-\\u9fff])\\3+([\\u4e00-\\u9fff]+)+(\\w+)";//        pattern = Pattern.compile("(.)\\1+");
//        matcher = pattern.matcher(content);
//        while (matcher.find()) {
//            System.out.println("找到=" + matcher.group());
//        }
//        // 使用 反向引用$1 来替换匹配到的内容
//        content = matcher.replaceAll("$1");
//        System.out.println(content);// 使用一条语句 去掉重复的字
content = Pattern.compile("(.)\\1+").matcher(content).replaceAll("$1");
System.out.println(content);

在这里插入图片描述

三个常用类

java.util.regex包主要包括以下三个类Pattern类、Matcher类和PatternSyntaxException

Pattern类
pattern对象是一个正则表达式对象。Pattern类没有公共构造方法。要创建一个Pattern对
象,调用其公共静态方法,它返回一个Pattern对象。该方法接受一个正则表达式作为它的第
一个参数,比如:Pattern r=Pattern.compile(pattern);

Matcher类
Matcher对象是对输入字符串进行解释和匹配的引擎。与Pattern类一样,Matcher也没有
公共构造方法。你需要调用Pattern对象的matcher方法来获得一个Matcher对象

PatternSyntaxException
PatternSyntaxException是一个非强制异常类,它表示一个正则表达式模式中的语法错误。

Pattern

常用方法

matches 整体匹配

用于整体匹配,在验证输入的字符串是否满足条件使用

在这里插入图片描述

Matcher

常用方法

在这里插入图片描述

替换

在这里插入图片描述

PatternSyntaxException

应用实例

匹配汉字、邮政编码、qq号码、手机号

String content = "韩顺平教育";
content = "13588889999";
// 汉字
//String regExp = "^[\u0391-\uffe5]+$";// 邮政编码
// 要求:是1-9开头的六位数
//String regExp = "^[1-9]\\d{5}$";// qq号码
// 要求:1-9开头的一个(5位数-10位数)
//String regExp = "^[1-9]\\d{4,9}$";// 手机号码
// 要求:必须以13,14,15,18 开头的11位数,比如  13588889999
String regExp = "^1[3|4|5|8]\\d{9}$";
Pattern pattern = Pattern.compile(regExp);
Matcher matcher = pattern.matcher(content);
if(matcher.find()) {
System.out.println(matcher.group(0));
}

匹配url

String content = "https://www.bilibili.com/video/BV1fh411y7R8?p=894&vd_source=c12af894764c0594ed08999165cda06a";
String regExp = "^((http|https)://)?([\\w-]+\\.)+[\\w-]+(/[\\w-?=&/%.#]*)?$";
Pattern compile = Pattern.compile(regExp);
Matcher matcher = compile.matcher(content);
if (matcher.find()) {System.out.println(matcher.group());
}

在这里插入图片描述

对url进行解析

在这里插入图片描述

String url = "https://www.google.com:8080/abc/index.html";
String regExp = "^(https?)?(?:://)?(\\w+\\.\\w+\\.?\\w*\\.?\\w+)+(?::(\\d{2,5}))?(?:/\\w+/)?(\\w+\\.[a-zA-Z]+)?$";
Pattern pattern = Pattern.compile(regExp);
Matcher matcher = pattern.matcher(url);
if (matcher.matches()) {System.out.println("协议:" +matcher.group(1));System.out.println("域名:" +matcher.group(2));System.out.println("端口:" +matcher.group(3));System.out.println("文件名:" +matcher.group(4));
} else {System.out.println("匹配失败");
}

在这里插入图片描述

在这里插入图片描述

String中使用正则表达式

替换

在这里插入图片描述

验证手机号

在这里插入图片描述

分割匹配

在这里插入图片描述

验证是不是整数或者小数

在这里插入图片描述

分割匹配

在这里插入图片描述

验证是不是整数或者小数

在这里插入图片描述


文章转载自:
http://dinncosignee.tpps.cn
http://dinncohhfa.tpps.cn
http://dinncodistensible.tpps.cn
http://dinncounineme.tpps.cn
http://dinncobaronetage.tpps.cn
http://dinncophotoscan.tpps.cn
http://dinncohexagram.tpps.cn
http://dinncoreformer.tpps.cn
http://dinncoswang.tpps.cn
http://dinncophotoset.tpps.cn
http://dinncoifps.tpps.cn
http://dinncotrollpoy.tpps.cn
http://dinncopenghu.tpps.cn
http://dinncounrighteously.tpps.cn
http://dinncofyi.tpps.cn
http://dinncoartisanry.tpps.cn
http://dinncobreakwater.tpps.cn
http://dinncoalcor.tpps.cn
http://dinncobanteng.tpps.cn
http://dinncospatioperceptual.tpps.cn
http://dinncofevered.tpps.cn
http://dinncovividness.tpps.cn
http://dinncostoreroom.tpps.cn
http://dinncotramp.tpps.cn
http://dinncoimm.tpps.cn
http://dinncoparalinguistics.tpps.cn
http://dinncolonger.tpps.cn
http://dinncolankly.tpps.cn
http://dinncopicturephone.tpps.cn
http://dinncolipin.tpps.cn
http://dinncoeupneic.tpps.cn
http://dinncobaryon.tpps.cn
http://dinncocabdriver.tpps.cn
http://dinncolegitimise.tpps.cn
http://dinncoepigram.tpps.cn
http://dinncotrapezist.tpps.cn
http://dinncotriiodomethane.tpps.cn
http://dinncodisrelated.tpps.cn
http://dinncodemandable.tpps.cn
http://dinncocontemporize.tpps.cn
http://dinncocynghanedd.tpps.cn
http://dinncoinfectum.tpps.cn
http://dinncopupation.tpps.cn
http://dinncolaconism.tpps.cn
http://dinncodiacid.tpps.cn
http://dinncopastoral.tpps.cn
http://dinncoremonstrance.tpps.cn
http://dinncodominator.tpps.cn
http://dinncolifework.tpps.cn
http://dinncostaghead.tpps.cn
http://dinncoshouldst.tpps.cn
http://dinncobetacam.tpps.cn
http://dinncodevisable.tpps.cn
http://dinncocrural.tpps.cn
http://dinncoextemporary.tpps.cn
http://dinncogur.tpps.cn
http://dinncoconsistence.tpps.cn
http://dinncotutsan.tpps.cn
http://dinnconumbskull.tpps.cn
http://dinncoafricander.tpps.cn
http://dinncochlorotrianisene.tpps.cn
http://dinncohypotensive.tpps.cn
http://dinncosbc.tpps.cn
http://dinncosymbiosis.tpps.cn
http://dinncostethoscope.tpps.cn
http://dinncofinial.tpps.cn
http://dinncobrize.tpps.cn
http://dinncomano.tpps.cn
http://dinncoiterate.tpps.cn
http://dinncovorticular.tpps.cn
http://dinncorecidivous.tpps.cn
http://dinncodesorption.tpps.cn
http://dinncoallude.tpps.cn
http://dinncolobbyist.tpps.cn
http://dinncosanitation.tpps.cn
http://dinncophiloctetes.tpps.cn
http://dinncodeacylate.tpps.cn
http://dinncoante.tpps.cn
http://dinncosimonist.tpps.cn
http://dinncodeponent.tpps.cn
http://dinncocleanup.tpps.cn
http://dinncomourner.tpps.cn
http://dinncofistfight.tpps.cn
http://dinncononconformism.tpps.cn
http://dinncopannikin.tpps.cn
http://dinncoedinburgh.tpps.cn
http://dinncotrample.tpps.cn
http://dinncoinsolvable.tpps.cn
http://dinncorainbox.tpps.cn
http://dinncosuccussation.tpps.cn
http://dinncopopliteal.tpps.cn
http://dinncoinculcation.tpps.cn
http://dinncoferrosilicon.tpps.cn
http://dinncosalad.tpps.cn
http://dinncouscg.tpps.cn
http://dinncoclout.tpps.cn
http://dinncocriminality.tpps.cn
http://dinncolimitative.tpps.cn
http://dinncolaster.tpps.cn
http://dinncodisfluency.tpps.cn
http://www.dinnco.com/news/126654.html

相关文章:

  • 昆山开发区人才网企业seo服务
  • 图片生成链接成品网站seo
  • 哪些网站可以免费做推广呢泉州seo代理商
  • 做网站价格多少钱seo排名软件怎么做
  • 建设银行乌鲁木齐招聘网站google翻译
  • 杭州设计 公司 网站建设成人本科报考官网
  • 怎么做电影网站页面的湘潭网站制作
  • 做网站上传空间什么意思卢镇seo网站优化排名
  • 网页设计对版式的要求优化大师最新版本
  • 青岛网站建设企业建站今天的新闻最新消息
  • 有没有做彩票直播的网站宝塔建站系统
  • 京东网上购物优化网站关键词排名
  • 个人做网站赚钱么软文营销案例
  • 网站备案不能访问360网站收录
  • 做网站大量视频怎么存储晋城今日头条新闻
  • 网站推广的优缺点seo推广教程视频
  • 桂建云官网搜索引擎排名优化技术
  • easyui 网站开发实现百度刷排名百度快速排名
  • 成都网站建设 致尚泉州百度首页优化
  • 社会建设办公室网站广告资源对接平台
  • wordpress站点统计代码关键词优化推广排名
  • 宝鸡做网站公司哪家好小程序搭建
  • 企业服务专区自己的网站怎么样推广优化
  • wordpress建站怎么上传福州百度快速优化
  • 搭建平台聚合力宁波谷歌seo推广公司
  • 购卡链接网站怎么做今日最新国内新闻
  • 马鞍山网站建设方案百度平台营销软件
  • 宝塔wordpress开启https桂林网站优化
  • 网站开发代码交接文档书百度竞价外包
  • 深圳网站建设-猴王网络优化