冷笑几声丶离去吧 关注:8贴子:504
  • 2回复贴,共1

【又开坑】Java正则表达式

只看楼主收藏回复



IP属地:北京1楼2016-10-24 16:26回复
    //上面一串等于下面一句
    boolean b = Pattern.compile("a*b").matcher("aaaab").matches();
    //还有更加精炼的版本:
    boolean b = Pattern.matches("a*b","aaaab");
    附上API文档:
    static Patterncompile(String regex, int flags)
    Compiles the given regular expression into a pattern with the given flags.
    static booleanmatches(String regex, CharSequence input)
    Compiles the given regular expression and attempts to match the given input against it.
    都是简化步骤的方法。


    IP属地:北京3楼2016-10-24 19:45
    回复
      Matcher类提供的方法:
      1 find() 返回不表字符串中是否包含了Pattern匹配的子串。
      2 group() 返回上一次与Pattern匹配的子串。
      3 start() 返回上一次匹配的子串的初始位置(当然,计算机中一切都是从0开始的)
      4 end() 返回上一次匹配的子串的结束位置+1
      5 lookingAt() 返回目标字符串前面部分是否和Pattern匹配
      6 matches() 返回整个目标字符串是否和Pattern匹配
      7 reset() 将现有的Matcher对象应用于一个新的字符序列(在不改变正则表达式的前提下)


      IP属地:北京4楼2016-10-24 19:50
      回复