简体   繁体   中英

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 (eg (?:\\"[^"]*?\\") ).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM