[英]Regex to get a specific query string variable in a URL
I have a URL like 我有一个类似的网址
server/area/controller/action/4/?param=2"
in which the server can be 服务器可以在其中
http://localhost/abc
https://test.abc.com
https://abc.om
I want to get the first character after "action/" which is 4 in the above URL, with a regex. 我想使用正则表达式在上述URL中的“ action /”之后获取第一个字符,该字符为4。 Is it possible with regex in js, or is there any way? js中的正则表达式可能吗,还是有什么办法?
这种方式将URL分割为/字符,并提取最后一个元素
var url = "server/area/controller/action/4/?param=2".split ('/').slice (-2,-1)[0];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.