I have a regular expression in which I’m trying to extract every group of letters that is not immediately followed by a “(” symbol. For example, the following regular expression operates on a mathematical formula that includes variable names (x, y, and z) and function names (movav and movsum), both of which are composed entirely of letters but where only the function names are followed by an “(“.
re.findall("[a-zA-Z]+(?!\()", "movav(x/2, 2)*movsum(y, 3)*z")
I would like the expression to return the array
['x', 'y', 'z']
but it instead returns the array
['mova', 'x', 'movsu', 'y', 'z']
I can see in theory why the regular expression would be returning the second result, but is there a way I can modify it to return just the array ['x', 'y', 'z']?
Another solution which doesn’t rely on word boundaries:
Check that the letters aren’t followed by either a
(or by another letter.