I'm trying to find an elegant way for matching negative and positive numbers at the same time, but not to capture the + sign while capturing the - sign.
So I have something like:
re.findall("([+-] \d+)x", "6x2 + 4x + 5 - 2x2 - 7x + 4 + 87x - 100x")
This gives me all multipliers for x, both positive and negative (great!). I would like the negative numbers to be - 2
, for example, but not return the plus sign for positive numbers (4
instead of + 4
). I failed with ?:
option, maybe I just used it incorrectly.