帮助一个简单的正则表达式

时间:2010-07-13 05:31:03

标签: javascript regex

我想从这个字符串中提取34。我怎么能这样做? (我将使用javascript)

#project_maincategory=3&project_subcategory=34&project_tags[]=70&project_tags[]=71&created_in=30

2 个答案:

答案 0 :(得分:5)

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]);

无论如何,它看起来像一个查询字符串,所以应该有一个更好的方法来解析/读取该字符串。见http://blog.falafel.com/Blogs/AdamAnderson/07-12-17/Parse_a_Query_String_in_JavaScript.aspx

答案 1 :(得分:0)

.*project_subcategory=(\d*).*