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

深圳网站建设 设计首选深圳市网站建设目标责任

深圳网站建设 设计首选深圳市,网站建设目标责任,办公室装修效果图图片大全,怎呀做网站作用 1.校验字符串是否满足规则 2.在一段文本中查找满足要求的内容 字符类(只匹配一个字符) [abc]只能是a,b,或c[^abc]除了a,b,c之外的任何字符[a-zA-Z]a到z A到Z,包括(范围)[a-d[m-p]]a到d,或m到p[a-z&&[def]]a-z和def的交集,为&am…

作用

1.校验字符串是否满足规则
2.在一段文本中查找满足要求的内容

字符类(只匹配一个字符)

[abc]只能是a,b,或c
[^abc]除了a,b,c之外的任何字符
[a-zA-Z]a到z A到Z,包括(范围)
[a-d[m-p]]a到d,或m到p
[a-z&&[def]]a-z和def的交集,为:d,e,f
[a-z&&[^bc]]a-z和非bc的交集,(等同于[ad-z])
[a-z&&[^m-p]]a到z和除了m到p的交集,(等同于[a-lq-z])

代码演示:

public class RegexDemo2 {public static void main(String[] args) {//public boolean matches(String regex):判断是否与正则表达式匹配,匹配返回true// 只能是a b cSystem.out.println("-----------1-------------");System.out.println("a".matches("[abc]")); // trueSystem.out.println("z".matches("[abc]")); // false// 不能出现a b cSystem.out.println("-----------2-------------");System.out.println("a".matches("[^abc]")); // falseSystem.out.println("z".matches("[^abc]")); // trueSystem.out.println("zz".matches("[^abc]")); //falseSystem.out.println("zz".matches("[^abc][^abc]")); //true// a到zA到Z(包括头尾的范围)System.out.println("-----------3-------------");System.out.println("a".matches("[a-zA-z]")); // trueSystem.out.println("z".matches("[a-zA-z]")); // trueSystem.out.println("aa".matches("[a-zA-z]"));//falseSystem.out.println("zz".matches("[a-zA-Z]")); //falseSystem.out.println("zz".matches("[a-zA-Z][a-zA-Z]")); //trueSystem.out.println("0".matches("[a-zA-Z]"));//falseSystem.out.println("0".matches("[a-zA-Z0-9]"));//true// [a-d[m-p]] a到d,或m到pSystem.out.println("-----------4-------------");System.out.println("a".matches("[a-d[m-p]]"));//trueSystem.out.println("d".matches("[a-d[m-p]]")); //trueSystem.out.println("m".matches("[a-d[m-p]]")); //trueSystem.out.println("p".matches("[a-d[m-p]]")); //trueSystem.out.println("e".matches("[a-d[m-p]]")); //falseSystem.out.println("0".matches("[a-d[m-p]]")); //false// [a-z&&[def]] a-z和def的交集。为:d,e,fSystem.out.println("----------5------------");System.out.println("a".matches("[a-z&[def]]")); //falseSystem.out.println("d".matches("[a-z&&[def]]")); //trueSystem.out.println("0".matches("[a-z&&[def]]")); //false// [a-z&&[^bc]] a-z和非bc的交集。(等同于[ad-z])System.out.println("-----------6------------_");System.out.println("a".matches("[a-z&&[^bc]]"));//trueSystem.out.println("b".matches("[a-z&&[^bc]]")); //falseSystem.out.println("0".matches("[a-z&&[^bc]]")); //false// [a-z&&[^m-p]] a到z和除了m到p的交集。(等同于[a-1q-z])System.out.println("-----------7-------------");System.out.println("a".matches("[a-z&&[^m-p]]")); //trueSystem.out.println("m".matches("[a-z&&[^m-p]]")); //falseSystem.out.println("0".matches("[a-z&&[^m-p]]")); //false}
}

预定义字符(只匹配一个字符)

.任何字符
\d一个数字:[0-9]
\D非数字:[^0-9]
\s一个空白字符:[\t\n\x0B\f\r]
\S非空白字符:[^\s]
\w[a-zA-Z_0-9] 英文、数字、下划线
\W[^\w] 一个非单词字符

代码演示:

public class RegexDemo3 {public static void main(String[] args) {// \ 转义字符 改变后面那个字符原本的含义//练习:以字符串的形式打印一个双引号//"在Java中表示字符串的开头或者结尾//此时\表示转义字符,改变了后面那个双引号原本的含义//把他变成了一个普普通通的双引号而已。System.out.println("\"");// \表示转义字符//两个\的理解方式:前面的\是一个转义字符,改变了后面\原本的含义,把他变成一个普普通通的\而已。System.out.println("c:Users\\moon\\IdeaProjects\\basic-code\\myapi\\src\\com\\itheima\\a08regexdemo\\RegexDemo1.java");//.表示任意一个字符System.out.println("你".matches("..")); //falseSystem.out.println("你".matches(".")); //trueSystem.out.println("你a".matches(".."));//true// \\d 表示任意的一个数字// \\d只能是任意的一位数字// 简单来记:两个\表示一个\System.out.println("a".matches("\\d")); // falseSystem.out.println("3".matches("\\d")); // trueSystem.out.println("333".matches("\\d")); // false//\\w只能是一位单词字符[a-zA-Z_0-9]System.out.println("z".matches("\\w")); // trueSystem.out.println("2".matches("\\w")); // trueSystem.out.println("21".matches("\\w")); // falseSystem.out.println("你".matches("\\w"));//false// 非单词字符System.out.println("你".matches("\\W")); // true}
}

数量词

x?X,0次或1次
X*X,0次或多次
X+X,1次或多次
x{n}X,正好n次
x{n,}X,至少n次
x{n,m}X,至少n但不超过m次

代码演示:

public class Test5 {public static void main(String[] args) {//必须是数字 字母 下划线 0次或1次System.out.println("".matches("\\w?"));//trueSystem.out.println("a".matches("\\w?"));//trueSystem.out.println("aa".matches("\\w?"));//false//必须是数字 字母 下划线 0次或多次System.out.println("".matches("\\w*"));//trueSystem.out.println("a".matches("\\w*"));//trueSystem.out.println("aa".matches("\\w*"));//true//必须是数字 字母 下划线 1次或多次System.out.println("".matches("\\w+"));//falseSystem.out.println("a".matches("\\w+"));//trueSystem.out.println("aa".matches("\\w+"));//true// 必须是数字 字母 下划线 至少 6位System.out.println("2442fsfsf".matches("\\w{6,}"));//trueSystem.out.println("244f".matches("\\w{6,}"));//false// 必须是数字和字符 必须是4位System.out.println("23dF".matches("[a-zA-Z0-9]{4}"));//trueSystem.out.println("23 F".matches("[a-zA-Z0-9]{4}"));//falseSystem.out.println("23dF".matches("[\\w&&[^_]]{4}"));//trueSystem.out.println("23_F".matches("[\\w&&[^_]]{4}"));//false// 必须是数字 字母 下划线 至少3但不超过6次System.out.println("".matches("\\w{3,6}"));//falseSystem.out.println("12".matches("\\w{3,6}"));//falseSystem.out.println("123".matches("\\w{3,6}"));//trueSystem.out.println("123456".matches("\\w{3,6}"));//trueSystem.out.println("1234567".matches("\\w{3,6}"));//false}
}


文章转载自:

http://zCPh4oZl.zfyym.cn
http://pJJBYgI0.zfyym.cn
http://FfR1rR4H.zfyym.cn
http://KnAG8vGS.zfyym.cn
http://hMJbVyvY.zfyym.cn
http://iNenebAT.zfyym.cn
http://0Xul6yfV.zfyym.cn
http://WjhWQsLF.zfyym.cn
http://fhUGFadt.zfyym.cn
http://J46sQKGI.zfyym.cn
http://gaaUkt76.zfyym.cn
http://XkM6eXKU.zfyym.cn
http://oVWJnH2Z.zfyym.cn
http://JRtK6i4I.zfyym.cn
http://yIdl6WeQ.zfyym.cn
http://ACRtnxkG.zfyym.cn
http://E4oWfk5w.zfyym.cn
http://QcYwPMEB.zfyym.cn
http://MkZzBd6Z.zfyym.cn
http://0TQtFxK2.zfyym.cn
http://XN78Bihx.zfyym.cn
http://zJ2IqUJY.zfyym.cn
http://KHxHdj9R.zfyym.cn
http://7sSQTLID.zfyym.cn
http://9wjIFimQ.zfyym.cn
http://4Da5fsk9.zfyym.cn
http://TeHVze1Y.zfyym.cn
http://ShjftONR.zfyym.cn
http://1u4m55Ka.zfyym.cn
http://xBmc5N3E.zfyym.cn
http://www.dtcms.com/wzjs/702017.html

相关文章:

  • 上海闵行刚刚发生的做网站建设优化的公司排名
  • 怎样发布自己的网站wordpress首页自定义缩略图
  • 网站宣传语深圳求职招聘网站
  • 360网站托管电商erp软件排名
  • 企业网站案例建设要求合肥有哪些做网站的
  • 中职校园网站建设建议网络营销策略包括哪些方面
  • 廊坊专业网站网站论文收录网站
  • 巴中建网站的公司南宁网络
  • 东莞大朗网站设计ui交互设计作品
  • 网站内容管理系统wordpress 图片浮动
  • 南平公司做网站怎么生成网页
  • 网站推广维护哪个网站专做进口商品的
  • 做网站用的笔记本配置宁波网站建设免费咨询
  • 网站建设公司 技术评估wordpress 如何 删除授权
  • win10 中国建设银行网站中国贸易网怎么样
  • 科技部网站seo网站排名优化公司哪家
  • 安全生产标准化建设网站微网站设计与开发教程
  • 成都培训学校网站建设去年做哪些网站能致富
  • 网站内页布局的不同上海建筑设计研究院有限公司官网
  • 网站排名监控工具做车贴网站
  • 网站备案查询不出来自媒体运营主要做什么
  • 自助网站建设工具网站建设就业
  • 律师网站建设哪家专业易云巢做网站公司
  • 东莞网站设计制作教程校园网站建设管理及责任表
  • 服务器网站绑定域名网站建设wordpress 作者墙
  • dedecms建设慕课网站专业建设 教学成果奖网站
  • 怎样在门户网站做网络推广河北邯郸专业网站建设
  • 克拉玛依建设局网站建一个网站的流程
  • 安徽网站建设开发电话潜江招聘资讯网
  • 与企业网站做接口在哪个网站做外贸生意好