I'm having trouble writing a regular expression for the following. I have a vector of literals (see RE_LIT) and I would like to find all the vectors in a line of text but I'm having difficulty writing the regular expression. Specifically I seem to have issues with the parenthesis acting as groups and not parenthesis.
RE_LABEL1 = r'[cvx]\d+(?![.]r)$'
RE_LABEL2 = r'v\d+\.r\d+'
RE_LABEL = r'(%s)|(%s)' % (RE_LABEL1, RE_LABEL2)
RE_LIT = r'!?%s' % RE_LABEL
RE_VEC = r'\[\s*(\s*%s\s*,?\s*)+\s*\]' % RE_LIT
Example string to match:
test = 'c1 = blah([v3,v4,v5.r1,!v6,v7,x8,v9,v10], [v1, v2], [x5.r1])'
Expected results:
> print re.findall(RE_VEC, test)
['[v3,v4,v5.r1,!v6,v7,x8,v9,v10]', '[v1, v2]']
Thank you ahead of time for your help.
\(. Your example isn't a very useful test, asr'\[[^]]+]'would work fine...