开发者

How to ignore special characters in named email format using regex in vbscript

I a have a vbscript that checks a named email format if correct using regular expression. However, upon named email strings with special character, my regular expression does not match below named email:

"Davé Lory, Sr." <jhonson@test.com>

I'm using the regular expression to check valid named email:

^\s*(([\"][\sa-zA-Z0-9_\-\.\'\,\&]*[\"])|([\sa-zA-Z0-9_\-\.\'\,\&]*))*\s*[\(<]\s*([A-Za-z0-9_\x27]+((\.|-)['A-Za-z0-9_\x27]+)*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+)\s*[\)>]\s*$

开发者_运维百科But it can't match if the named email contain special a character like é or È etc..

How can I ignore this special characters in regular expression?

Please help.

Thanks.


You can not ignore them, you need to match them.

You can try this one here

^\s*((\"[^"]*?\")|([\sa-zA-Z0-9_\-\.\'\,\&]*))*\s*[\(<]\s*([A-Za-z0-9_\x27]+((\.|-)['A-Za-z0-9_\x27]+)*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+)\s*[\)>]\s*$

I removed your [\"][\sa-zA-Z0-9_\-\.\'\,\&]*[\"] with

\"[^"]*?\"
  1. you don't need square brackets around a single character

  2. [^"]*? is a lazy match that will match anything that is not a " till the next "

You can see it online here at Rubular

I have not checked the rest of the expression, what I have seen on rubular is that there are many capturing groups. If you don't need the result then you can make them non capturing by ?: after the opening bracket (e.g. (?:\"[^"]*?\")).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜