以下是我的文字 -
Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of "de Finibus Bonorum et Malorum" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This should also match () and ( ).
我正在尝试匹配文本 -
- (善与恶的极端)
- ()
- ( )
我的正则表达式 - \(.\)
不起作用。
我还尝试了 \(*\)
,它与 ()
的 ()
, )
匹配,并且(善恶之极)
的)
。让我知道我在这里做错了什么。
最佳答案
您需要一个量词*
来匹配括号内的零个或多个字符。也使其变得懒惰 ?
,因此只要到达第一个右括号 \(.*?\)
:
var s = 'Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of "de Finibus Bonorum et Malorum" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This should also match () and ( ).'
console.log(
s.match(/\(.*?\)/g)
)
关于javascript - 匹配括号中是否包含文本 - 正则表达式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46393875/