Regular exp to validate email in C

梦想与她 提交于 2019-12-07 07:36:26

Your problem is the four instances of the sequence (?. That's meaningless - the ( starts a new sub-regex and you can't have ? at the start of a regex.

In case you're interested,

I saw recently the Perfect email regex finally found post on Hacker News and
it's about the Comparing E-mail Address Validating Regular Expressions.

The regexs,

// James Watts and Francisco Jose Martin Moreno are the first to develop one which  
// passes all of the tests.
/^([\w\!\#$\%\&\'\*\+\-\/\=\?\^\`{\|\}\~]+\.)*[\w\!\#$\%\&\'\*\+\-\/\=\?\^\`{\|\}\~]+@((((([a-z0-9]{1}[a-z0-9\-]{0,62}[a-z0-9]{1})|[a-z])\.)+[a-z]{2,6})|(\d{1,3}\.){3}\d{1,3}(\:\d{1,5})?)$/i

// Arluison Guillaume has also improved Warren Gaebel's regex.
// This one will work in JavaScript:
/^[-a-z0-9~!$%^&*_=+}{\'?]+(\.[-a-z0-9~!$%^&*_=+}{\'?]+)*@([a-z0-9_][-a-z0-9_]*(\.[-a-z0-9_]+)*\.(aero|arpa|biz|com|coop|edu|gov|info|int|mil|museum|name|net|org|pro|travel|mobi|[a-z][a-z])|([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}))(:[0-9]{1,5})?$/i 
Newton Pasqualini Filho

I use this POSIX expression in standard C:

const char *reg_exp = "^([a-z0-9])(([-a-z0-9._])*([a-z0-9]))*@([a-z0-9])"
                      "(([a-z0-9-])*([a-z0-9]))+(.([a-z0-9])([-a-z0-9_-])?"
                      "([a-z0-9])+)+$";
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!