Reputation: 817
I tried various combinations but unsuccesfull at figuring out correct regex pattern.
Basically I want to capture patterns like examples below:
and so on..
I wanted to capture variable,function1,param1,function2,param2 from this
So far I have below regex which does not work completely
\{\{([^{}.]+)(\.([^{}]+)\{([^{}]+)\})*\}\}
If I try to apply above pattern on example 3, I get below groups
I was expecting somthing as below,
PS: you can check without writing code at http://regexr.com/3e4st
Upvotes: 1
Views: 120
Reputation: 12649
Okay, so the reason why your thing doesn't work, is because you're basically only capturing one instance of the thing in general, which means each capture group can only return one instance of what you want. So what's needed is the global variable or your equivalent in whatever language you're using.
Example: https://regex101.com/r/pO8xN2/3
Upvotes: 1
Reputation: 338316
The number of groups in a regex match is fixed. See an older post of mine with more explanation. In your case that number is 4.
When a group matches repeatedly, you will usually only be able to access the value of the last occurrence in the string. That's what you see with your issue: function2
, param2
.
Some regex engines allow accessing previous group captures (for example the one in .NET). The majority don't. Whether you can solve your issue easily or not strictly depends on your regex engine.
Upvotes: 1