每天一点正则表达式积累(三)

来源:互联网 发布:股票走势预测 python 编辑:程序博客网 时间:2024/04/30 13:50
        p(" \n\r\t".matches("\\s{4}"));//true 说名\s 空白字符:[ \t\n\x0B\f\r]        p(" ".matches("\\S"));//false 说明\S 非空白字符:[^\s] 所以是false        p("a_8".matches("\\w{3}"));//true        p("abc888&^%".matches("[a-z]{1,3}\\d+[&^#%]+"));//true 说明[a-z]{1,3}代表字符出现到三次,\\d+数字出现多个[&^#%]+中括号里面的四者之一出现一次或者多次        //或者这样写        p("abc888&^%".matches("[a-z]{3}\\d{3}[&^%]+"));//true        p("\\".matches("\\\\"));//true注意\\前面的指的是一个\         // p("\\".matches("\\"));//如果后面的是两个\\则不对,提示Unexpected internal error near index 1。语法不对       // 注意\\p{Upper}或\\p{Lower}只能判断一个字符,而不是字符串        p("a".matches("\\p{Lower}"));//true 说明\p{Lower} 小写字母字符:[a-z]         p("dafdsfad".matches("\\w{2,}"));//true        p("dafdsAfad".matches("[a-z]+"));//false        p("dafdsfad".matches("[a-z]+"));//true        //可以用下面方法匹配小写字符串,当然这样写多此一举了,因为[a-z]+本身就代表着多个小写字母        p("dafdsfaddfdsf".matches("[a-z&&\\p{Lower}]+"));//true        p("A".matches("\\p{Lower}"));//false        p("aA".matches("\\p{Lower}"));//false        p("aA".matches("\\p{Lower}\\p{Upper}"));//true        p("A".matches("\\p{Upper}"));//true 说明\p{Upper} 大写字母字符:[A-Z]        p("Ab".matches("\\p{Upper}"));//false        p("Ab".matches("\\p{Upper}\\p{Lower}"));//true        p(" ".matches("\\p{Space}")); //true \p{Space} 空白字符:[ \t\n\x0B\f\r] 

原创粉丝点击