Marc Rasmussen
Marc Rasmussen

Reputation: 20555

JavaScript regex returns -1 when > 0 is expected

Okay so i have the following string:

Aktiv landbruger / Regler AL

With this string i attempt to run the following regex:

/Regler AL/i

However once i run string.search('/Regler AL/i')

it returns -1

However when i attempt this on

https://regex101.com/

it returns 0 as it should.

So why is my javascript returning -1

Upvotes: 0

Views: 32

Answers (1)

potatopeelings
potatopeelings

Reputation: 41065

Remove the single quotes around the regex

"Aktiv landbruger / Regler AL".search(/Regler AL/i)

Upvotes: 5

Related Questions