[英]What exactly is this regular expression doing?
I'm looking over some code and found the following regex: 我正在查看一些代码,发现以下正则表达式:
var querystring = querystring.replace(/[^&]+=\.?(?:&|$)/g, '')
Is this taking the querystring and replacing all values that begin with an ampersand or question mark with a space? 这是否采用查询字符串并将所有以“&”或问号开头的值替换为空格? Is there more going on here that I don't see?
还有更多我看不到的事情吗?
You're logical explanation is much appreciated and help gain a little more understanding of regex. 您的逻辑解释将不胜感激,有助于您对正则表达式有更多的了解。 Thanks!
谢谢!
It appears to remove those parameters from the query string whose value is: 似乎从查询字符串中删除了这些参数,其值是:
.
.
For example: 例如:
"remove1=&remove2=.&keep1=..&keep2=a&keep3=b".replace(/[^&]+=\.?(?:&|$)/g, '')
// returns "keep1=..&keep2=a&keep3=b"
[^&]+
one or more non "&" characters [^&]+
一个或多个非“&”字符
=
a literal "=" character =
文字“ =”字符
\\.?
an optional "." 可选的“。”
(?:&|$)
a "&" character or the end of the string (?:&|$)
一个“&”字符或字符串的结尾
Would eg match 例如匹配
Foobar=.&
Foobar的=。&
A=A =
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.