John Paul De Guzman
John Paul De Guzman

Reputation: 3

Regex matching and grouping results

I'm working on a pre-processor and I have a piece of code needed to get a match.

Example input:

padding: eval((20%/2)+5)) eval(30);
width: eval(100%/2);
font-family: font-find("Helvetica");

I need to match and group the matches base on the string provided. Expected output should be:

[0] = eval((20%/2)+5)
[1] = eval(30)
[2] = eval(100%/2)
[3] = font-find("Helvetica")

The content of the item inside the parenthesis can be any value. It's easy to match the items for output 2 - 3, but I can't get to group the values for 0 and 1.

I'm writing the code in PHP. "eval" and "font-find" are arbitrary functions.

Is this even possible?

Upvotes: 0

Views: 75

Answers (1)

cdtits
cdtits

Reputation: 1128

preg_match_all('/(\w+\(\S*\))/', $str, $matches);

Upvotes: 1

Related Questions