Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
java模式匹配器语法,选择性地无法识别字符串_Java_Regex_Pattern Matching - Fatal编程技术网

java模式匹配器语法,选择性地无法识别字符串

java模式匹配器语法,选择性地无法识别字符串,java,regex,pattern-matching,Java,Regex,Pattern Matching,我正在使用java模式匹配器梳理出形式为“XXX”(“XXX”,“XXX”)的字符串。我不只是想要文本,即XXX 这是我目前正在使用的: Pattern p = Pattern.compile("'(.*?)'\\('(.*?)','(.*?)'\\)\\."); 它能够与此相匹配: 'prevents'('scurvy','vitamin C'). 'contains'('vitamin C','orange'). 'contains'('vitamin C','sauerkraut').

我正在使用java模式匹配器梳理出形式为“XXX”(“XXX”,“XXX”)的字符串。我不只是想要文本,即XXX

这是我目前正在使用的:

Pattern p = Pattern.compile("'(.*?)'\\('(.*?)','(.*?)'\\)\\.");
它能够与此相匹配:

'prevents'('scurvy','vitamin C').
'contains'('vitamin C','orange').
'contains'('vitamin C','sauerkraut').
'isa'('fruit','orange').
'improves'('health','fruit').
但无法识别这一点,尽管它们的格式相同

'take place in'('the grand hall of the hong kong convention', 'the ceremony').
'attend by'('some # guests', 'the grand hall of the hong kong convention').
'seat on'('the central dais', 'principal representatives of both countries').
'be'('mr jiang', 'representing china').
'be'('hrh', 'britain').
'be more than'('# distinguished guests', 'the principal representatives').
'end with'('the playing of the british national anthem', 'hong kong').
'follow at'('the stroke of midnight', 'this').
'take part in'('the ceremony', 'both countries').
'start at about'('# pm', 'the ceremony').
'end about'('# am', 'the ceremony').
'lower'('the british hong kong flag', '# royal hong kong police officers').
'raise'('the sar flag', 'another #').
'leave for'('the royal yacht britannia', 'the #').
'hold by'('the chinese and british governments', 'the handover of hong kong').
'rise over'('this land', 'the regional flag of the hong kong special administrative region of the people \'s republic of china').
'cast eye on'('hong kong', 'the world').
'hold on'('schedule', 'the # governments').
'be festival for'('the chinese nation', 'this').
'go in'('the annals of history', 'july # , #').
'become master of'('this chinese land', 'the hong kong compatriots').
'enter era of'('development', 'hong kong').
'remember'('mr deng xiaoping', 'history').
'be along'('the course', 'it').
'resolve'('the hong kong question', 'we').
这是什么原因

有没有一个网站可以专门演示我的正则表达式,因为它应用于java模式匹配器?比如regexr.com
或者一些简单易懂的文档也不错,我的谷歌搜索结果非常零碎且不连贯。

因为所有文档都在逗号后有空格

因此,我建议您使用
\s*
(匹配零个或多个空格)或
\s?
(匹配可选空格)

例如:

 'prevents'('scurvy','vitamin C').
                     ^
                     | - no space
但是


我建议您学习所有格匹配符和否定字符组-我怀疑您的模式对于不匹配的文本来说会相当慢。您可以在线测试您的正则表达式,例如这里的啊!哈哈,该死。锐利的目光应该是双重的\\在s出现之前。哦,我忘了双重逃逸
\s
@flavius\u valens参考资料做什么?正则表达式语法?@flavius_valens是学习正则表达式的最佳站点。。
 'prevents'('scurvy','vitamin C').
                     ^
                     | - no space
'take place in'('the grand hall of the hong kong convention', 'the ceremony').
                                                             ^
                                                             |- space