views:

249

answers:

2

Hi,

I can't figure out how to search for a string containing something like "[1]", for some reason this doesn't work:

var regExp = '/\[[1-9]\]/';
var search = string.search(regExp); // returns -1

I've searched all over for a solution but can't find anything...

+7  A: 
var regExp = /\[[1-9]\]/;
var search = string.search(regExp);

try it without the '

AutomatedTester
A: 

I think it's the way you're actually attempting to match it. Try this:

string="something[1]";
if(string.match(/\[[1-9]\]/gi)) alert("Your string has brackets with a number inside!"); //Alerts correctly
Salty