-2

I am trying to get the values within parenthesis in a given expression,

Example :

((1 or 2) and (3 and 4))

Output should be like this :

1 => 1 or 2
2 => 3 and 4
3 => 1 or 2 and 3 and 4

Please can anyone help me to get regexp to get the above result ?

US-1234
  • 1,519
  • 4
  • 24
  • 61
  • @HamZa it is nothing duplicate like this – Satish Sharma May 22 '14 at 09:24
  • 1
    @SatishSharma It is, at least for the very poor information the OP has provided. Also, this is not specifically targeted to you, but don't encourage this kind of posts by upvoting it out of sympathy. It's low quality: the op should at least provide what he has tried. We're not a free coding service. – HamZa May 22 '14 at 09:27
  • yes you are right but my question is that how it is duplicate – Satish Sharma May 22 '14 at 09:36

1 Answers1

0
((?<=\()[^)]+)

should do the job for you. But for the third result you will have to

substitute [()]

with nothing.

worth mentioning is the use of g modifier

demo here : http://regex101.com/r/eE7hU3

aelor
  • 10,892
  • 3
  • 32
  • 48
  • `g` modifier doesn't exist in php. Use `preg_match_all()` instead of `preg_match()`. Another cool feature of php :) – HamZa May 22 '14 at 09:29
  • @HamZa yes you are right. I just pointed the OP to use preg_match_all, since in my demo `g`lobal is present – aelor May 22 '14 at 09:30