Negative forecast always returns true
I am using this regex
/(?!results)/i
As I understand it, it will match any line that does not contain the word "result". However, when I try
/(?!results)/i.test('basketball results')
it returns true
. How do I match strings that don't contain words results
?
This regex matches every position without results
following it. See demo .
To match an expression that doesn't contain results
you need to use ^(?!.*results.*$).*
. See another demo .
You can use the simple one indexOf
here. It will return -1
if the substring is not contained in the string and is zero or greater:
"basketball results".indexOf('results') == -1