正则表达式不匹配新行 [英] Regular expression is not matching new lines
本文介绍了正则表达式不匹配新行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下正则表达式:
"^((?!([\w!#$%&'*+\-/=?\^_`{|}~]+(\.[\w!#$%&'*+\-/=?\^_`{|}~]+)*@((([\-\w]+\.)+[a-zA-Z]{2,4})|(([0-9]{1,3}\.){3}[0-9]{1,3})))).)*$"
但它也不匹配新行:
https://regex101.com/r/nT6wK0/1
有新行时如何使其匹配的任何想法?
Any ideas how to make it match when there is a new line?
推荐答案
.
在和实际上意味着
除换行符外的所有字符.(来源)
All but a line break character. (source)
用[\S\s]
代替,表示
所有空格字符和所有非空格字符;所以所有字符.
All spacing characters and all non-spacing characters; so all characters.
然后它似乎起作用了.您可以使用其他变体,例如 [\W\w]
、[\D\d]
、...
Then it seems to work. You could have used other variants like [\W\w]
, [\D\d]
,...
所以正确"的正则表达式(请不要相信我的话,首先测试一下)是:
So the "correct" regex (please don't take my word for it, first test this) is:
^((?!([\w!#$%&'*+\-/=?\^_`{|}~]+(\.[\w!#$%&'*+\-/=?\^_`{|}~]+)*@((([\-\w]+\.)+[a-zA-Z]{2,4})|(([0-9]{1,3}\.){3}[0-9]{1,3}))))[\S\s])*$
这篇关于正则表达式不匹配新行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文