如何正则表达式到括号?

How to regex a phrase up to a parenthesis?

我正在尝试对一个名为 reason 的组进行正则表达式,我已经非常接近了,但不太明白最后一部分。我想对 Reason: 之间的所有内容进行正则表达式,但不包括 (winRc=999)

中的第一个括号

正在提取的字符串如下。

原因:用户名或密码不正确。 (winRc=999)

我希望有一个表达式显示:

"Reason: The user name or password is incorrect." 的完整匹配 'Reason' 组 "The user name or password is incorrect."

匹配

你可以使用类似于@CodeManiac 上面提到的东西

/Reason: ([^(]*)/    

来自 regex101 的演示

https://regex101.com/r/J2ddFQ/1

利用负数的优势class,非常强大。