Cod-nes Posted October 24, 2009 Share Posted October 24, 2009 I don't know why isn't my code not working. var str="doamin.com/index.php?something=bah";var patt=new RegExp("?");var pat=new RegExp("&");document.write("Test if we find " + patt + " in " + str + ": ")if (patt.test(str)==true){document.write("Match found!");}else if(pat.test(str)==true){document.write("Match found!");}else{document.write("Match not found");} Link to comment Share on other sites More sharing options...
Ingolme Posted October 24, 2009 Share Posted October 24, 2009 I don't know why isn't my code not working. var str="doamin.com/index.php?something=bah";var patt=new RegExp("?");var pat=new RegExp("&");document.write("Test if we find " + patt + " in " + str + ": ")if (patt.test(str)==true){document.write("Match found!");}else if(pat.test(str)==true){document.write("Match found!");}else{document.write("Match not found");} "?" is a reserved character in regular expressions. I also recommend not using the RegExp() constructor because it can lead to confusion (you need extra backslashes to escape things.Try this:var patt = /\?/;var pat = /&/; Link to comment Share on other sites More sharing options...
Cod-nes Posted October 24, 2009 Author Share Posted October 24, 2009 Thanks. ^^ Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.