Dylan_Larkin
Dylan_Larkin

Reputation: 513

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!

Upvotes: 3

Views: 55

Answers (1)

Tim Biegeleisen
Tim Biegeleisen

Reputation: 521073

Try this regex:

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

Demo here:

Regex101

Upvotes: 4

Related Questions