Dylan_Larkin Dylan_Larkin - 1 month ago 9
C++ Question

simple regex seemingly not working c++

Trying to find a regex to indicate whether the right side of an equation has an 'M' or not. This is what I have:

^[^=\\s@0-9;(D|A)]+(?==)


Here's how I translate this:

^ - assert start of line

[everything in brackets] - match one or more characters NOT in these brackets

(?==) - positive lookahead... but now that I'm actually writing this out I think this might be the error.


I've been developing my regex's on www.regex101.com on the php default (I know, dumb, but I can't find an online C++ version). It's just hard to predict the behavior doing it this way, and when I have something that seems like it would work, it only partially works.

So,

M=D-M // should indicate M on RHS
D=D+A // should not indicate M on RHS
D=A // should not indicate M on RHS


It's possible my code has a subtle bug not related to the Regex, but I'm pretty sure that's not the case. It works for dozens of cases with only 2-3 errors. Let's assume its related to regex.

P.S. I'm trying to parse some simple .asm files...

HELP!

Answer

Try this regex:

^[^=]+=([^=]*[M][^=]*)$

Demo here:

Regex101