根据Javadoc(根据我的理解),matches()即使它找到了它正在寻找的东西,它也会搜索整个字符串,并find()在它找到它所寻找的内容时停止.
如果这个假设是正确matches()的find(),除非你想要计算它找到的匹配数,否则我无法看到你想要使用的代替.
在我看来,String类应该具有find()而不是matches()作为内置方法.
总结一下:
matches()而不是find()?我想匹配和查找被空格或特殊字符包围的单词索引。例如:
To find: test
this is input test : True
this is#input_ : True
this isinput : False
thisisinputtest: False
this @test is right: True.
Run Code Online (Sandbox Code Playgroud)
我如何匹配它并找到索引。我当前的正则表达式失败:(?i)[^a-zA-Z0-9]test[^a-zA-Z0-9]