0

An anchor tag similar to this is clicked.

<a href="go.php?id=3aaa">Click Me</a>

$(this)[0] contains a string similar to http://localhost/www/go.php?3aaa

I wish to strip the "3" and "aaa" (values change according to what is clicked) into their own variables and test for their values.

user674073
  • 159
  • 1
  • 4
  • 14

1 Answers1

0

Try this:

var match = $(this)[0].match(/\?(\d{1,})(\w*)/);

then match[1] has the digit (3 like above) and match[2] has the string (aaa like above);

moe
  • 28,814
  • 4
  • 19
  • 16
  • Thanks! That works perfectly... but only if the path remains one level deep. How would you suggest amending the regex to handle unknown directory levels? (eg. http://localhost/www/newlevel/go.php?5bbb ) What is the regex for matching all chars after the question mark? – user674073 Mar 25 '11 at 14:47
  • I tried it with the new link you gave and it still works, this regex matches number(s)+character(s) that are after a '?'. It doesnt care what is before the '?'. – moe Mar 25 '11 at 16:52