`
jusi
  • 浏览: 4705 次
  • 性别: Icon_minigender_1
  • 来自: 天津
社区版块
存档分类
最新评论

Difference between matches() and find() in Java Regex Matcher

    博客分类:
  • java
 
阅读更多

I am trying to understand the difference between matches() and find().

 

matches() tries to match the expression against the entire string and implicitly add a ^ at the start and $ at the end of your pattern, meaning it will not look for a substring. Hence the output of this code:

public static void main(String[] args) throws ParseException {
    Pattern p = Pattern.compile("\\d\\d\\d");
    Matcher m = p.matcher("a123b");
    System.out.println(m.find());
    System.out.println(m.matches());

    p = Pattern.compile("^\\d\\d\\d$");
    m = p.matcher("123");
    System.out.println(m.find());
    System.out.println(m.matches());
}

 

output:

true
false
true
true

 

分享到:
评论

相关推荐

    Regex Matcher-1.12-Crx4Chrome.com.crx

    Regex Matcher Chrome正则表达式匹配插件

    java 正则表达式 Java Regex.rar

    java 正则表达式 java 正则表达式 java 正则表达式 java 正则表达式 java 正则表达式 java 正则表达式 java 正则表达式

    Regex Matcher-crx插件

    方便的工具,用于创建和测试正则表达式(regex) 极简主义编辑器,用于针对一组示例文本创建和测试正则表达式(regex)。 针对模式测试正则表达式,例如:-电子邮件地址-IP地址-URL-用户名以及许多其他常见和唯一的...

    article-regex-primer.rar_The Few

    Java Regex follows the same basic principles used in other languages, just withdi erent access methods, and some subtledi erences with the patterns. This primer is aimed towards developers already ...

    UiPath - Matches and Regex - Simple and Complete Tutorial.srt

    UiPath - Matches and Regex - Simple and Complete Tutorial.srt

    regex_matcher

    regex_matcher 此存储库以spacy快速有效地实现了正则表达式匹配器。 此类具有与spacy Matcher和PhraseMatcher相同的行为,但是对基础文本而不是单个标记(不同于Matcher )进行操作,并允许使用正则表达式语法(与...

    Java.Regex.Crash.Course.B015YXJCMY.epub

    Chapter 1: Our First Steps in Java Regular Expressions Chapter 2: Basic Characters Used in Regex Chapter 3: Java Regex Classes Chapter 4: Regex for Username Chapter 5: Regex for Password Chapter 6: ...

    matcher中find、matches、lookingAt的区别

    Java1.8 API中给的定义: matches() :尝试将整个区域与模式进行匹配。 find() :尝试找到匹配模式的输入序列的下一个子序列。 lookingAt() :尝试将...import java.util.regex.Matcher; import java.util.regex.Patte

    JAVA正则表达式--Pattern和Matcher

    JAVA正则表达式--Pattern和Matcher 现在JDK1.4里终于有了自己的正则表达式API包,JAVA程序员可以免去找第三方提供的正则表达式库的周折了,我们现在就马上来了解一下这个SUN提供的­迟来恩物- -对我来说确实如此。...

    find+ | Regex find -in- page工具。「find+ | Regex Find-in-Page Tool」-crx插件

    支持正则表达式的谷歌Chrome的find-in-page扩展。 {find +}是Google Chrome浏览器的功能强大的“页面查找”扩展程序,具有通过正则表达式搜索网页或文档的功能。 它的外观和行为与本地CTRL-F函数非常相似,但是为了...

    java 正则表达试

    import org.apache.oro.text.regex.PatternMatcher; import org.apache.oro.text.regex.Perl5Compiler; import org.apache.oro.text.regex.Perl5Matcher; import org.apache.oro.text.regex.Perl5Substitution; ...

    java regex例子

    学习regex的好例子,感觉挺好的。 学习regex的好例子,感觉挺好的。

    JS cookie Java cookie regex 整理结果

    自己整理的关于java和jscookie的实际应用,以及regex的应用,绝对好用。

    Regex Quick Syntax Reference

    It demonstrates regex syntax in a well-organized format that can be used as a handy reference, showing you how to execute regexes in many languages, including JavaScript, Python, Java, and C#. ...

    javaregex.chm

    NULL 博文链接:https://hedajia.iteye.com/blog/1679933

    Java Regex To Use

    NULL 博文链接:https://log-cd.iteye.com/blog/199661

    正则表达式 测试 工具Regex Testor

    {x,y} Matches the preceding element between x and y times 值得一提的是()代表子匹配,有些环境中gr(a|e)y Matches gray or grey 还支持许多常见的转义字符 \b,\B,\c,\d,\D,\f,\n,\r,\s,\S,\t,\v,\w,\W,\x,\u...

    find+ | Regex Find-in-Page Tool-crx插件

    使用{find +},您可以匹配对页面中文文本的任何合法JavaScript正常表达式,请使用查找和替换以替换页面中的文本,将正则表达式的剪贴板复制到剪贴板,存储常用表达式,并配置扩展名你喜欢的方式。作为软件开发人员,...

    java统计字符串出现次数算法--StringCounter(算法源码)

    import java.util.regex.Matcher; import java.util.regex.Pattern; public class StringCounter { /** * 正则统计字符串出现次数 * * @param source * @param regexNew * @return int */ public ...

    Packt.Java.9.Regular.Expressions

    You will begin by discovering what regular expressions are and how they work with Java. This easy-to-follow guide is a ... Finally, you will master tips, tricks, and best practices in regex with Java

Global site tag (gtag.js) - Google Analytics