0

I tried and stuck to this formula which only only work on 1 pair of brackets:

preg_match('#\((.*?)\)#', $text, $match);
print $match[1];

What I want to do is parse the text after the last open parenthesis before the first close parenthesis.

For example, I have equation like this:

1+(2+(3+(5-6)))+(7-8)

The text that would be parsed is "5-6".

Kevin
  • 79
  • 2
  • 11

1 Answers1

1

Match ( > anything except ( or ) > )

$text = '1+(2+(3+(5-6)))+(7-8)';
preg_match('/\(([^\(\)]+)\)/', $text, $match);
var_dump($match);
tbraun89
  • 2,246
  • 3
  • 25
  • 44
SAJID
  • 38
  • 7