I am trying to make an algorithm for regex that finds uncalculated calculations such as ’15+15′, however; it should not match ’15+15=30′
So far I have made it work to find calculations such as 15+15, however; it also matches 15+15=30
What I have got so far is
\d{1,9}\+\d{1,9}
I tried with
\d{1,9}\+\d{1,9}[^=]
But it didn’t really work as I expected.
I am using the .net ‘Regex’ class
What you need is a negative lookahead:
This asserts that the pattern is not followed by
=. The\bis a word boundary that makes sure that you don’t match15+1in15+15=30(because5is not=).The reason why your attempt with the negated character class doesn’t work is that it needs a non-
=character after the match.