If {} are supposed to contain anyting then maybe this will work?
(\w+)\(([a-zA-Z0-9_\-~]+(\{.*\})?),(.+)\)\.
Question
I want to extract some groups from command-like strings with the form:
So a comma can be present in the first argument!
Since the second argument is always beginning with a digit, I could match for the first argument commas which are not followed by a number, but I just can't do it with lookahead :(
Here is my tries so far:
(\w+)\(([a-zA-Z0-9_\-\{\}~]+)(,(\d+(\.\d+)?))?\)\.
... but example 3 won't match this one.
(\w+)\(([a-zA-Z0-9_\-\{\}~\,(?!\d)]+)(,(\d+(\.\d+)?))?\)\.
... this one won't let me catch the groups > 2 (negative lookahead doesn't affect the first comma)
Here's the Debuggex example
Any help will be appreciated! Many thanks in advance :)
Solution
If {} are supposed to contain anyting then maybe this will work?
(\w+)\(([a-zA-Z0-9_\-~]+(\{.*\})?),(.+)\)\.
OTHER TIPS
This seems to do the trick:
(.*?)(?:\(|\)|,(?=\d))
Expl.: Match anything up to either a '(', ')' or a ',' followed by a digit.
If you want arbitrary spaces to be allowed:
\s*(.*?)\s*(?:\(|\)|,(?=\d))\s*
Use global flag to get all instances.
Regards