正则表达式中,\(\((.+?)\)\)和\(\(\s*(.+?)\s*\)\)有什么区别?

4
当我在RegExr工具中尝试\(\((.+?)\)\)\(\(\s*(.+?)\s*\)\)时,我找不到区别。两者都突出了相同的文本。有没有\s*的区别是什么?或者为什么需要\s*
我使用了以下示例文本。
I ((   a verb, past tense   )) to the sandwich shop across the street for lunch
yesterday. I go there at least ((a number)) times a week. They have the best
Philly Cheesesteak, full of ((a plural noun)) and ((a plural noun)) and gooey,
stringy ((a noun)). 
1个回答

4
第二个模式是带有明确空白字符的模式 (\s*),从捕获组中删除前导和尾随的空白字符。然而,全局匹配不会改变。
要查看与gskinner的不同行为,您可以尝试使用两种模式进行替换:"#$1#" (其中$1是捕获组)。

谢谢,我忘记了这个单词。 - Casimir et Hippolyte

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接