PHP:匹配字符串中最后的parethesized单词?

$string = 'Foo (Bar) (Baz)'
preg_match('#\((.*?)\)#', $string, $match);

In the above PHP, $match is returned as

array ( 0 => '(Bar)', 1 => 'Bar', )

Is it possible to alter the regex so it returns:

array ( 0 => '(Baz)', 1 => 'Baz', )

.i.e. the final word in parenthesis.

Thanks.

#.*\((.*?)\)#

try this.this should do it.

or

#\((.*?)\)(?!.*\()#

You can use this regex which uses lookaheads and behinds to make it more clear

/(?<=\()(.*?)(?=\($)/

This is what I would do:

\(((?!.*\().*?)\)

Regular expression visualization

Debuggex Demo