我有这个字符串
"fname=Nerison&mname=Sayson&lname=Pitogo&extname=&email=son2xp2go04221%40gmail.com&bday=1991-01-04&gender=MALE&address=Libertad%2C+Butuan+City"
使用正则表达式,如何确定除了扩展名之外还有空值?
答案 0 :(得分:1)
使用这个简单的正则表达式:
\b(?!extname)\w+=(?:&|$)
请参阅demo,它匹配两个空变量,但不匹配extname
解释正则表达式
\b # the boundary between a word char (\w) and
# something that is not a word char
(?! # look ahead to see if there is not:
extname # 'extname'
) # end of look-ahead
\w+ # word characters (a-z, A-Z, 0-9, _) (1 or
# more times (matching the most amount
# possible))
= # '='
(?: # group, but do not capture:
& # '&'
| # OR
$ # before an optional \n, and the end of
# the string
) # end of grouping