javascript - Ask a question about using regular expressions to obtain URL parameters
天蓬老师
天蓬老师 2017-06-12 09:29:39
0
2
983
var url = "https://api.xxx.com/search?name=xxx&age=xxx&sex=xxx";

Given this url, match the parameter string following ? (not including?) through a regular expression. Please tell me how to write the regular expression. Xiaobai asks for advice~~

天蓬老师
天蓬老师

欢迎选择我的课程,让我们一起见证您的进步~~

reply all(2)
漂亮男人

Because js does not support forward lookahead syntax, it cannot use the syntax (?<=?), so we can only save the country through curves:

var url = "https://api.xxx.com/search?name=xxx&age=xxx&sex=xxx";
var reg = /\?[^"/]+/
var result = reg.exec(url)
para = result[0].slice(1)
console.log(para)

// 输出:
name=xxx&age=xxx&sex=xxx
我想大声告诉你

This does not require regularization.

pos = str.indexOf('?')

str.substring(pos+1)

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template