troubles with regex

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
newmember
Forum Contributor
Posts: 252
Joined: Fri Apr 02, 2004 12:36 pm

troubles with regex

Post by newmember »

here is query string:
"?sc=aa1&st=001010"
and i'm trying to match
either "?st=001010" or "&st=001010"
with:

Code: Select all

location.search.match("/(&|\?)st=(0|1){6}/");
i tried also:

Code: Select all

location.search.indexOf("/(&|\?)st=(0|1){6}/");
all browsers i'm testing with tell me that something wrong with my regex...
but online regex verifiers say everything is ok...

can anyone please tell me where i'm wrong?
thanks
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

you don't have a regex in Javascript. Regexes of this syntax, do not have quotes around them.

Why are you using Javascript and regexes to find this information? You can just use the QueryString object ([google]Javascript QueryString object[/google]) or better yet, use php to do it.
Post Reply