0

My array consists of thousands of values and I need to get the '[State]' string out of it. I use regex for fetching various strings (from the same array) and they all work fine (for instance the following:

'^\/\/[ ]{1}[0-9]{3,4}').

...so in order to get the mentioned '[State]' I created the following Regex:

'^\[State\]'

And it works fine in Regex tester ...but as soon as I pass this regex in my javascript code:

var reg = new RegExp(searchElement); 

and then match test it:

if (reg.test(file[el]))

I get other things returned like: [Test]... so obviously something's wrong with the expression. As mentioned other expressions work flawlessly... And I don't understand why it works in the online regex tester and it doesn't in my code...

tom33pr
  • 853
  • 2
  • 12
  • 30

0 Answers0