且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

正则表达式不匹配新行

更新时间:2022-06-25 22:06:35

. 在和实际上意味着

除换行符外的所有字符.(来源)

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])*$

regex101 演示.