Googlebot
Googlebot

Reputation: 15673

How to get the contents of parenthesis by regex?

I want to get the contents of parenthesis within a string in PHP by regular expression. I tried this regex

preg_match_all('/\((.*)?\)/', $string, $match);

But this get the content between the first ( and last ). How can I get the content of every ( )separately to make the array of match?

Upvotes: 0

Views: 126

Answers (2)

SERPRO
SERPRO

Reputation: 10067

You need to change the .* with [^\)]*

Upvotes: 1

user142162
user142162

Reputation:

preg_match_all('/\(([^)]*)\)/', $string, $match);

Upvotes: 1

Related Questions