Reputation:
I have some code strings that I need to extract some data from, but specific data at that.
The strings are always in the same format.
List Options
here.@groups
here. The string I need at the end will always start with @
(List Options((join ", ", @groups))
I have tried:
^\((\w+).*, (@\w+)\)\)$
But it only gives me the word List
Upvotes: 1
Views: 49
Reputation: 70732
This should work well for you.
^\(([^(]+)[^@]+([^)]+)\)+$
See working demo
Regular expression:
^ the beginning of the string
\( look and match '('
( group and capture to \1:
[^(]+ any character except: '(' (1 or more times)
) end of \1
[^@]+ any character except: '@' (1 or more times)
( group and capture to \2:
[^)]+ any character except: ')' (1 or more times)
) end of \2
\)+ ')' (1 or more times)
$ before an optional \n, and the end of the string
Upvotes: 2
Reputation: 9529
try this one
^\(([^\(]+?)\(.*?@([^\)]+?)\)
or if you need the @ sign also captured, just move it inside the 2nd capturing group
^\(([^\(]+?)\(.*?(@[^\)]+?)\)
Upvotes: 1