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~~
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
Because js does not support forward lookahead syntax, it cannot use the syntax
(?<=?)
, so we can only save the country through curves:This does not require regularization.
pos = str.indexOf('?')
str.substring(pos+1)