我需要检查针对某些文本的模式(我必须检查我的模式是否在很多文本中)。Java正则表达式匹配模式
这是我的例子
String pattern = "^[a-zA-Z ]*toto win(\\W)*[a-zA-Z ]*$";
if("toto win because of".matches(pattern))
System.out.println("we have a winner");
else
System.out.println("we DON'T have a winner");
对于我的测试,该模式必须匹配,但使用正则表达式我不匹配。 必须匹配:
" toto win bla bla"
"toto win because of"
"toto win. bla bla"
"here. toto win. bla bla"
"here? toto win. bla bla"
"here %dfddfd . toto win. bla bla"
必须不匹配:
" -toto win bla bla"
" pretoto win bla bla"
我尝试使用我的正则表达式来做到这一点,但它不工作。
你能指点我做错了什么吗?
引号是否会出现在输入字符串中? – Cylian
它可以是任何东西。这是一个普通的文本 –
请[不要添加签名和标语到您的帖子](http://stackoverflow.com/faq#signatures)。你也经常拼错“很多”。 “a”和“lot”之间有一个空格。 – meagar