역사상 가장 복잡 한 메 일 주 소 를 검증 하 는 정규 표현 식

152326 단어
전환 하 다
https://linux.cn/article-5963-1.html
정규 표현 식 으로 메 일 주 소 를 검증 하 는 것 은 간단 한 일 인 것 같 지만, 규범 에 맞 는 메 일 주 소 를 완벽 하 게 검증 하려 면 복잡 할 수도 있다.
메 일 주소 의 규범 은 RFC 5322 。사이트 가 있어 요. emailregex.com 각종 프로 그래 밍 언어 에서 메 일 주 소 를 검증 하 는 정규 표현 식 을 전문 적 으로 보 여 줍 니 다. 그 중에서 많은 정규 표현 식 은 제 가 들 어 본 적 이 없 는 복잡 한 것 입 니 다. 이 사 이 트 를 하 는 프로그래머 가 메 일 로 이 일 을 검증 하 는 데 얼마나 큰 상 처 를 입 었 는 지 말 하고 싶 습 니 다.
사실 제품 환경 에서 일반적으로 이렇게 복잡 한 정규 표현 식 으로 99.99% 를 정확하게 할 필요 가 없다.일반적으로 실행 효율 과 테스트 보급률 에 있어 서 간단 한 버 전 만 있 으 면 됩 니 다.

  
  
  
  
  1. /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i

그럼 더 엄밀 하고 복잡 한 정규 표현 식 을 살 펴 보 자.
메 일 주 소 를 검증 하 는 일반적인 정규 표현 식 (RFC 5322 표준 에 부합)

  
  
  
  
  1. (?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\])

다양한 언어 가 정규 표현 식 에 대한 지원 이 다 르 고 문법 차이 와 도달 율 이 다 르 기 때문에 언어 마다 정규 표현 식 이 다 릅 니 다.
Python
이것 은 간단 한 버 전 입 니 다.

  
  
  
  
  1. r"(^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$)"

Javascript
이것 은 좀 복잡 하 다.

  
  
  
  
  1. /^[-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

Swift

  
  
  
  
  1. [A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,6}

PHP
PHP 의 이 버 전 은 더욱 복잡 해 지고 도달 율 이 더 높 습 니 다.

  
  
  
  
  1. /^(?!(?:(?:\x22?\x5C[\x00-\x7E]\x22?)|(?:\x22?[^\x5C\x22]\x22?)){255,})(?!(?:(?:\x22?\x5C[\x00-\x7E]\x22?)|(?:\x22?[^\x5C\x22]\x22?)){65,}@)(?:(?:[\x21\x23-\x27\x2A\x2B\x2D\x2F-\x39\x3D\x3F\x5E-\x7E]+)|(?:\x22(?:[\x01-\x08\x0B\x0C\x0E-\x1F\x21\x23-\x5B\x5D-\x7F]|(?:\x5C[\x00-\x7F]))*\x22))(?:\.(?:(?:[\x21\x23-\x27\x2A\x2B\x2D\x2F-\x39\x3D\x3F\x5E-\x7E]+)|(?:\x22(?:[\x01-\x08\x0B\x0C\x0E-\x1F\x21\x23-\x5B\x5D-\x7F]|(?:\x5C[\x00-\x7F]))*\x22)))*@(?:(?:(?!.*[^.]{64,})(?:(?:(?:xn--)?[a-z0-9]+(?:-[a-z0-9]+)*\.){1,126}){1,}(?:(?:[a-z][a-z0-9]*)|(?:(?:xn--)[a-z0-9]+))(?:-[a-z0-9]+)*)|(?:\[(?:(?:IPv6:(?:(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){7})|(?:(?!(?:.*[a-f0-9][:\]]){7,})(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,5})?::(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,5})?)))|(?:(?:IPv6:(?:(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){5}:)|(?:(?!(?:.*[a-f0-9]:){5,})(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,3})?::(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,3}:)?)))?(?:(?:25[0-5])|(?:2[0-4][0-9])|(?:1[0-9]{2})|(?:[1-9]?[0-9]))(?:\.(?:(?:25[0-5])|(?:2[0-4][0-9])|(?:1[0-9]{2})|(?:[1-9]?[0-9]))){3}))\]))$/iD

Perl / Ruby
PHP 버 전, Perl, Ruby 에 불복 하여 더욱 엄밀 할 수 있 습 니 다.

  
  
  
  
  1. (?:(?:\r
    )?[ \t])*(?:(?:(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r
    )?[ \t]
  2. )+|\Z|(?=[\["()<>@,;:\\".\[\]]))|"(?:[^\"\r\\]|\\.|(?:(?:\r
    )?[ \t]))*"(?:(?:
  3. \r
    )?[ \t])*)(?:\.(?:(?:\r
    )?[ \t])*(?:[^()<>@,;:\\"
    .\[\] \000-\031]+(?:(?:(
  4. ?:\r
    )?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|"(?:[^\"\r\\]|\\.|(?:(?:\r
    )?[
  5. \t]))*"(?:(?:\r
    )?[ \t])*))*@(?:(?:\r
    )?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\0
  6. 31]+(?:(?:(?:\r
    )?[ \t])+|\Z|(?=[\["
    ()<>@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\
  7. ](?:(?:\r
    )?[ \t])*)(?:\.(?:(?:\r
    )?[ \t])*(?:[^()<>@,;:\\"
    .\[\] \000-\031]+
  8. (?:(?:(?:\r
    )?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:
  9. (?:\r
    )?[ \t])*))*|(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r
    )?[ \t])+|\Z
  10. |(?=[\["()<>@,;:\\".\[\]]))|"(?:[^\"\r\\]|\\.|(?:(?:\r
    )?[ \t]))*"(?:(?:\r
    )
  11. ?[ \t])*)*\<(?:(?:\r
    )?[ \t])*(?:@(?:[^()<>@,;:\\"
    .\[\] \000-\031]+(?:(?:(?:\
  12. r
    )?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r
    )?[
  13. \t])*)(?:\.(?:(?:\r
    )?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r
    )
  14. ?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r
    )?[ \t]
  15. )*))*(?:,@(?:(?:\r
    )?[ \t])*(?:[^()<>@,;:\\"
    .\[\] \000-\031]+(?:(?:(?:\r
    )?[
  16. \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r
    )?[ \t])*
  17. )(?:\.(?:(?:\r
    )?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r
    )?[ \t]
  18. )+|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r
    )?[ \t])*))*)
  19. *:(?:(?:\r
    )?[ \t])*)?(?:[^()<>@,;:\\"
    .\[\] \000-\031]+(?:(?:(?:\r
    )?[ \t])+
  20. |\Z|(?=[\["()<>@,;:\\".\[\]]))|"(?:[^\"\r\\]|\\.|(?:(?:\r
    )?[ \t]))*"
    (?:(?:\r

  21. )?[ \t])*)(?:\.(?:(?:\r
    )?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:
  22. \r
    )?[ \t])+|\Z|(?=[\["
    ()<>@,;:\\".\[\]]))|"(?:[^\"\r\\]|\\.|(?:(?:\r
    )?[ \t
  23. ]))*"(?:(?:\r
    )?[ \t])*))*@(?:(?:\r
    )?[ \t])*(?:[^()<>@,;:\\"
    .\[\] \000-\031
  24. ]+(?:(?:(?:\r
    )?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\](
  25. ?:(?:\r
    )?[ \t])*)(?:\.(?:(?:\r
    )?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?
  26. :(?:(?:\r
    )?[ \t])+|\Z|(?=[\["
    ()<>@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?
  27. :\r
    )?[ \t])*))*\>(?:(?:\r
    )?[ \t])*)|(?:[^()<>@,;:\\"
    .\[\] \000-\031]+(?:(?
  28. :(?:\r
    )?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|"(?:[^\"\r\\]|\\.|(?:(?:\r
    )?
  29. [ \t]))*"(?:(?:\r
    )?[ \t])*)*:(?:(?:\r
    )?[ \t])*(?:(?:(?:[^()<>@,;:\\".\[\]
  30. \000-\031]+(?:(?:(?:\r
    )?[ \t])+|\Z|(?=[\["
    ()<>@,;:\\".\[\]]))|"(?:[^\"\r\\]|
  31. \\.|(?:(?:\r
    )?[ \t]))*"(?:(?:\r
    )?[ \t])*)(?:\.(?:(?:\r
    )?[ \t])*(?:[^()<>
  32. @,;:\\".\[\] \000-\031]+(?:(?:(?:\r
    )?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|"
  33. (?:[^\"\r\\]|\\.|(?:(?:\r
    )?[ \t]))*"
    (?:(?:\r
    )?[ \t])*))*@(?:(?:\r
    )?[ \t]
  34. )*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r
    )?[ \t])+|\Z|(?=[\["
    ()<>@,;:\\
  35. ".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r
    )?[ \t])*)(?:\.(?:(?:\r
    )?[ \t])*(?
  36. :[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r
    )?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[
  37. \]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r
    )?[ \t])*))*|(?:[^()<>@,;:\\".\[\] \000-
  38. \031]+(?:(?:(?:\r
    )?[ \t])+|\Z|(?=[\["
    ()<>@,;:\\".\[\]]))|"(?:[^\"\r\\]|\\.|(
  39. ?:(?:\r
    )?[ \t]))*"(?:(?:\r
    )?[ \t])*)*\<(?:(?:\r
    )?[ \t])*(?:@(?:[^()<>@,;
  40. :\\".\[\] \000-\031]+(?:(?:(?:\r
    )?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[([
  41. ^\[\]\r\\]|\\.)*\](?:(?:\r
    )?[ \t])*)(?:\.(?:(?:\r
    )?[ \t])*(?:[^()<>@,;:\\"
  42. .\[\] \000-\031]+(?:(?:(?:\r
    )?[ \t])+|\Z|(?=[\["
    ()<>@,;:\\".\[\]]))|\[([^\[\
  43. ]\r\\]|\\.)*\](?:(?:\r
    )?[ \t])*))*(?:,@(?:(?:\r
    )?[ \t])*(?:[^()<>@,;:\\"
    .\
  44. [\] \000-\031]+(?:(?:(?:\r
    )?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[([^\[\]\
  45. r\\]|\\.)*\](?:(?:\r
    )?[ \t])*)(?:\.(?:(?:\r
    )?[ \t])*(?:[^()<>@,;:\\".\[\]
  46. \000-\031]+(?:(?:(?:\r
    )?[ \t])+|\Z|(?=[\["
    ()<>@,;:\\".\[\]]))|\[([^\[\]\r\\]
  47. |\\.)*\](?:(?:\r
    )?[ \t])*))*)*:(?:(?:\r
    )?[ \t])*)?(?:[^()<>@,;:\\"
    .\[\] \0
  48. 00-\031]+(?:(?:(?:\r
    )?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|"(?:[^\"\r\\]|\\
  49. .|(?:(?:\r
    )?[ \t]))*"
    (?:(?:\r
    )?[ \t])*)(?:\.(?:(?:\r
    )?[ \t])*(?:[^()<>@,
  50. ;:\\".\[\] \000-\031]+(?:(?:(?:\r
    )?[ \t])+|\Z|(?=[\["
    ()<>@,;:\\".\[\]]))|"(?
  51. :[^\"\r\\]|\\.|(?:(?:\r
    )?[ \t]))*"(?:(?:\r
    )?[ \t])*))*@(?:(?:\r
    )?[ \t])*
  52. (?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r
    )?[ \t])+|\Z|(?=[\["()<>@,;:\\".
  53. \[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r
    )?[ \t])*)(?:\.(?:(?:\r
    )?[ \t])*(?:[
  54. ^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r
    )?[ \t])+|\Z|(?=[\["
    ()<>@,;:\\".\[\]
  55. ]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r
    )?[ \t])*))*\>(?:(?:\r
    )?[ \t])*)(?:,\s*(
  56. ?:(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r
    )?[ \t])+|\Z|(?=[\["()<>@,;:\\
  57. ".\[\]]))|"(?:[^\"\r\\]|\\.|(?:(?:\r
    )?[ \t]))*"
    (?:(?:\r
    )?[ \t])*)(?:\.(?:(
  58. ?:\r
    )?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r
    )?[ \t])+|\Z|(?=[
  59. \["()<>@,;:\\".\[\]]))|"(?:[^\"\r\\]|\\.|(?:(?:\r
    )?[ \t]))*"(?:(?:\r
    )?[ \t
  60. ])*))*@(?:(?:\r
    )?[ \t])*(?:[^()<>@,;:\\"
    .\[\] \000-\031]+(?:(?:(?:\r
    )?[ \t
  61. ])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r
    )?[ \t])*)(?
  62. :\.(?:(?:\r
    )?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r
    )?[ \t])+|
  63. \Z|(?=[\["()<>@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r
    )?[ \t])*))*|(?:
  64. [^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r
    )?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\
  65. ]]))|"(?:[^\"\r\\]|\\.|(?:(?:\r
    )?[ \t]))*"
    (?:(?:\r
    )?[ \t])*)*\<(?:(?:\r
    )
  66. ?[ \t])*(?:@(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r
    )?[ \t])+|\Z|(?=[\["
  67. ()<>@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r
    )?[ \t])*)(?:\.(?:(?:\r
    )
  68. ?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r
    )?[ \t])+|\Z|(?=[\["()<>
  69. @,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r
    )?[ \t])*))*(?:,@(?:(?:\r
    )?[
  70. \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r
    )?[ \t])+|\Z|(?=[\["
    ()<>@,
  71. ;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r
    )?[ \t])*)(?:\.(?:(?:\r
    )?[ \t]
  72. )*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r
    )?[ \t])+|\Z|(?=[\["()<>@,;:\\
  73. ".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r
    )?[ \t])*))*)*:(?:(?:\r
    )?[ \t])*)?
  74. (?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r
    )?[ \t])+|\Z|(?=[\["
    ()<>@,;:\\".
  75. \[\]]))|"(?:[^\"\r\\]|\\.|(?:(?:\r
    )?[ \t]))*"(?:(?:\r
    )?[ \t])*)(?:\.(?:(?:
  76. \r
    )?[ \t])*(?:[^()<>@,;:\\"
    .\[\] \000-\031]+(?:(?:(?:\r
    )?[ \t])+|\Z|(?=[\[
  77. "()<>@,;:\\".\[\]]))|"(?:[^\"\r\\]|\\.|(?:(?:\r
    )?[ \t]))*"
    (?:(?:\r
    )?[ \t])
  78. *))*@(?:(?:\r
    )?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r
    )?[ \t])
  79. +|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r
    )?[ \t])*)(?:\
  80. .(?:(?:\r
    )?[ \t])*(?:[^()<>@,;:\\"
    .\[\] \000-\031]+(?:(?:(?:\r
    )?[ \t])+|\Z
  81. |(?=[\["()<>@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r
    )?[ \t])*))*\>(?:(
  82. ?:\r
    )?[ \t])*))*)?;\s*)

Perl 5.10 및 이후 버 전
위의 판본, 응, 내 가 천 서 라 고 해도 돼?어차피 난 읽 을 생각 이 없어.물론 새 버 전의 Perl 언어 는 더 읽 기 쉬 운 버 전이 있 습 니 다. (정말 입 니까?) 

  
  
  
  
  1. /(?(DEFINE)
  2. (?<address> (?&mailbox) | (?&group))
  3. (?<mailbox> (?&name_addr) | (?&addr_spec))
  4. (?<name_addr> (?&display_name)? (?&angle_addr))
  5. (?<angle_addr> (?&CFWS)? < (?&addr_spec) > (?&CFWS)?)
  6. (?<group> (?&display_name) : (?:(?&mailbox_list) | (?&CFWS))? ;
  7. (?&CFWS)?)
  8. (?<display_name> (?&phrase))
  9. (?<mailbox_list> (?&mailbox) (?: , (?&mailbox))*)
  10. (?<addr_spec> (?&local_part) \@ (?&domain))
  11. (?<local_part> (?&dot_atom) | (?&quoted_string))
  12. (?<domain> (?&dot_atom) | (?&domain_literal))
  13. (?<domain_literal> (?&CFWS)? \[ (?: (?&FWS)? (?&dcontent))* (?&FWS)?
  14. \] (?&CFWS)?)
  15. (?<dcontent> (?&dtext) | (?&quoted_pair))
  16. (?<dtext> (?&NO_WS_CTL) | [\x21-\x5a\x5e-\x7e])
  17. (?<atext> (?&ALPHA) | (?&DIGIT) | [!#\$%&'*+-/=?^_`{|}~])
  18. (?<atom> (?&CFWS)? (?&atext)+ (?&CFWS)?)
  19. (?<dot_atom> (?&CFWS)? (?&dot_atom_text) (?&CFWS)?)
  20. (?<dot_atom_text> (?&atext)+ (?: \. (?&atext)+)*)
  21. (?<text> [\x01-\x09\x0b\x0c\x0e-\x7f])
  22. (?<quoted_pair> \\ (?&text))
  23. (?<qtext> (?&NO_WS_CTL) | [\x21\x23-\x5b\x5d-\x7e])
  24. (?<qcontent> (?&qtext) | (?&quoted_pair))
  25. (?<quoted_string> (?&CFWS)? (?&DQUOTE) (?:(?&FWS)? (?&qcontent))*
  26. (?&FWS)? (?&DQUOTE) (?&CFWS)?)
  27. (?<word> (?&atom) | (?&quoted_string))
  28. (?<phrase> (?&word)+)
  29. # Folding white space
  30. (?<FWS> (?: (?&WSP)* (?&CRLF))? (?&WSP)+)
  31. (?<ctext> (?&NO_WS_CTL) | [\x21-\x27\x2a-\x5b\x5d-\x7e])
  32. (?<ccontent> (?&ctext) | (?&quoted_pair) | (?&comment))
  33. (?<comment> \( (?: (?&FWS)? (?&ccontent))* (?&FWS)? \) )
  34. (?<CFWS> (?: (?&FWS)? (?&comment))*
  35. (?: (?:(?&FWS)? (?&comment)) | (?&FWS)))
  36. # No whitespace control
  37. (?<NO_WS_CTL> [\x01-\x08\x0b\x0c\x0e-\x1f\x7f])
  38. (?<ALPHA> [A-Za-z])
  39. (?<DIGIT> [0-9])
  40. (?<CRLF> \x0d \x0a)
  41. (?<DQUOTE> ")
  42. (?<WSP> [\x20\x09])
  43. )
  44. (?&address)/x

Ruby ( )

Ruby , :

/\A([\w+\-].?)+@[a-z\d\-]+(\.[a-z]+)*\.[a-z]+\z/i

.NET

——.NET :


  
  
  
  
  1. ^\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$

grep

grep , , :


  
  
  
  
  1. $ grep -E -o "\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,6}\b" filename.txt

SQL Server 

SQL Server , , , :


  
  
  
  
  1. select email
  2. from table_name where
  3. patindex ('%[ &'',":;!+=\/()<>]%', email) > 0 -- Invalid characters
  4. or patindex ('[@.-_]%', email) > 0 -- Valid but cannot be starting character
  5. or patindex ('%[@.-_]', email) > 0 -- Valid but cannot be ending character
  6. or email not like '%@%.%' -- Must contain at least one @ and one .
  7. or email like '%..%' -- Cannot have two periods in a row
  8. or email like '%@%@%' -- Cannot have two @ anywhere
  9. or email like '%.@%' or email like '%@.%' -- Cannot have @ and . next to each other
  10. or email like '%.cm' or email like '%.co' -- Camaroon or Colombia? Typos.
  11. or email like '%.or' or email like '%.ne' -- Missing last letter

Oracle PL/SQL

? “ ” :


  
  
  
  
  1. SELECT email
  2. FROM table_name
  3. WHERE REGEXP_LIKE (email, '[A-Z0-9._%-]+@[A-Z0-9._%-]+\.[A-Z]{2,4}');

MySQL

, :


  
  
  
  
  1. SELECT * FROM `users` WHERE `email` NOT REGEXP '^[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$';

, ?

 


좋은 웹페이지 즐겨찾기