Alex Rivera | Logout

php preg_match between bracket

Asked 2011-10-11T17:12:48.667
10

i want to use preg_match to find text between bracket for example: $varx = "(xx)";

final output will be $match = 'xx';

another example $varx = "bla bla (yy) bla bla";

final output will be something like this $match = 'yy';

in other words it strips out bracket. i'm still confusing with regular expression but found that sometimes preg match is more simple solution. searching other example but not meet my need.

Edit
Report

1 Answer

13

Try something like this:

preg_match('/(?<=\()(.+)(?=\))/is', $subject, $match);

Now it will capture newlines.

answered 2011-10-11T17:17:54.077

Your Answer