views:

61

answers:

2

Hi, i want to extract 34 from this string. How Can i done that ? (i will use javascript)

#project_maincategory=3&project_subcategory=34&project_tags[]=70&project_tags[]=71&created_in=30
+5  A: 
var src   = "#project_maincategory=3&project_subcategory=34&project_tags[]=70&project_tags[]=71&created_in=30",
    match = /project_subcategory=(\d+)/g.exec(src);

    alert(match[1]);

Anyways, it looks like a query string so there should be a better way to parse/read that string. See http://blog.falafel.com/Blogs/AdamAnderson/07-12-17/Parse_a_Query_String_in_JavaScript.aspx

jAndy
It doesn't work. Returns undefined.
mTuran
@mTuran: whoops, my bad. fixed!
jAndy
Thank you......
mTuran
A: 

.*project_subcategory=(\d*).*

thomasfedb
The `.*` at the start and the end aren't needed.
icktoofay
Thanks for the tip.
thomasfedb