[LUNI] Valid email Regex

Scott Thomason SThomaso at phmining.com
Wed Nov 28 11:06:22 CST 2001


Here's the regex itself as created by the program ... brace yourself:

  (?: [\040\t] |  \(
                     (?:  [^\\\x80-\xff\n\015()]  |  \\ [^\x80-\xff]  |  \( (?:  [^\\\x80-\xff\n\015()]  |  \\ [^\x80-\xff]  )* \)  )*
               \)  )*                          # optional leading comment
                (?:    (?:
  [^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff]+    # some number of atom characters...
  (?![^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff]) # ..not followed by something that could be part of an atom
 |
        " (?:                      # opening quote...
              [^\\\x80-\xff\n\015"]                #   Anything except backslash and quote
              |                     #    or
               \\ [^\x80-\xff]           #   Escaped something (something != CR)
                             )* "  # closing quote
 )                    # initial word
        (?:  (?: [\040\t] |  \(
                     (?:  [^\\\x80-\xff\n\015()]  |  \\ [^\x80-\xff]  |  \( (?:  [^\\\x80-\xff\n\015()]  |  \\ [^\x80-\xff]  )* \)  )*
               \)  )*  \.  (?: [\040\t] |  \(
                     (?:  [^\\\x80-\xff\n\015()]  |  \\ [^\x80-\xff]  |  \( (?:  [^\\\x80-\xff\n\015()]  |  \\ [^\x80-\xff]  )* \)  )*
               \)  )*   (?:
  [^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff]+    # some number of atom characters...
  (?![^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff]) # ..not followed by something that could be part of an atom
 |
        " (?:                      # opening quote...
              [^\\\x80-\xff\n\015"]                #   Anything except backslash and quote
              |                     #    or
               \\ [^\x80-\xff]           #   Escaped something (something != CR)
                             )* "  # closing quote
 )  )*        # further okay, if led by a period
  (?: [\040\t] |  \(
                     (?:  [^\\\x80-\xff\n\015()]  |  \\ [^\x80-\xff]  |  \( (?:  [^\\\x80-\xff\n\015()]  |  \\ [^\x80-\xff]  )* \)  )*
               \)  )*  @  (?: [\040\t] |  \(
                     (?:  [^\\\x80-\xff\n\015()]  |  \\ [^\x80-\xff]  |  \( (?:  [^\\\x80-\xff\n\015()]  |  \\ [^\x80-\xff]  )* \)  )*
               \)  )*    (?:
  [^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff]+    # some number of atom characters...
  (?![^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff]) # ..not followed by something that could be part of an atom
 |   \[                         # [
                   (?: [^\\\x80-\xff\n\015\[\]] |  \\ [^\x80-\xff]  )*    #    stuff
                   \]                        #           ]
 )                           # initial subdomain
              (?:                                  #
                  (?: [\040\t] |  \(
                     (?:  [^\\\x80-\xff\n\015()]  |  \\ [^\x80-\xff]  |  \( (?:  [^\\\x80-\xff\n\015()]  |  \\ [^\x80-\xff]  )* \)  )*
               \)  )*  \.                        # if led by a period...
                  (?: [\040\t] |  \(
                     (?:  [^\\\x80-\xff\n\015()]  |  \\ [^\x80-\xff]  |  \( (?:  [^\\\x80-\xff\n\015()]  |  \\ [^\x80-\xff]  )* \)  )*
               \)  )*   (?:
  [^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff]+    # some number of atom characters...
  (?![^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff]) # ..not followed by something that could be part of an atom
 |   \[                         # [
                   (?: [^\\\x80-\xff\n\015\[\]] |  \\ [^\x80-\xff]  )*    #    stuff
                   \]                        #           ]
 )                     #   ...further okay
              )*
             # address
                    |                     #  or
                      (?:
  [^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff]+    # some number of atom characters...
  (?![^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff]) # ..not followed by something that could be part of an atom
 |
        " (?:                      # opening quote...
              [^\\\x80-\xff\n\015"]                #   Anything except backslash and quote
              |                     #    or
               \\ [^\x80-\xff]           #   Escaped something (something != CR)
                             )* "  # closing quote
 )             # one word, optionally followed by....
              (?:
                  [^()<>@,;:".\\\[\]\x80-\xff\000-\010\012-\037]  |  # atom and space parts, or...
                   \(
                     (?:  [^\\\x80-\xff\n\015()]  |  \\ [^\x80-\xff]  |  \( (?:  [^\\\x80-\xff\n\015()]  |  \\ [^\x80-\xff]  )* \)  )*
               \)       |  # comments, or...

        " (?:                      # opening quote...
              [^\\\x80-\xff\n\015"]                #   Anything except backslash and quote
              |                     #    or
               \\ [^\x80-\xff]           #   Escaped something (something != CR)
                             )* "  # closing quote
      # quoted strings
              )*
   <  (?: [\040\t] |  \(
                     (?:  [^\\\x80-\xff\n\015()]  |  \\ [^\x80-\xff]  |  \( (?:  [^\\\x80-\xff\n\015()]  |  \\ [^\x80-\xff]  )* \)  )*
               \)  )*                     # leading <
                    (?:  @  (?: [\040\t] |  \(
                     (?:  [^\\\x80-\xff\n\015()]  |  \\ [^\x80-\xff]  |  \( (?:  [^\\\x80-\xff\n\015()]  |  \\ [^\x80-\xff]  )* \)  )*
               \)  )*    (?:
  [^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff]+    # some number of atom characters...
  (?![^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff]) # ..not followed by something that could be part of an atom
 |   \[                         # [
                   (?: [^\\\x80-\xff\n\015\[\]] |  \\ [^\x80-\xff]  )*    #    stuff
                   \]                        #           ]
 )                           # initial subdomain
              (?:                                  #
                  (?: [\040\t] |  \(
                     (?:  [^\\\x80-\xff\n\015()]  |  \\ [^\x80-\xff]  |  \( (?:  [^\\\x80-\xff\n\015()]  |  \\ [^\x80-\xff]  )* \)  )*
               \)  )*  \.                        # if led by a period...
                  (?: [\040\t] |  \(
                     (?:  [^\\\x80-\xff\n\015()]  |  \\ [^\x80-\xff]  |  \( (?:  [^\\\x80-\xff\n\015()]  |  \\ [^\x80-\xff]  )* \)  )*
               \)  )*   (?:
  [^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff]+    # some number of atom characters...
  (?![^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff]) # ..not followed by something that could be part of an atom
 |   \[                         # [
                   (?: [^\\\x80-\xff\n\015\[\]] |  \\ [^\x80-\xff]  )*    #    stuff
                   \]                        #           ]
 )                     #   ...further okay
              )*

             (?:  (?: [\040\t] |  \(
                     (?:  [^\\\x80-\xff\n\015()]  |  \\ [^\x80-\xff]  |  \( (?:  [^\\\x80-\xff\n\015()]  |  \\ [^\x80-\xff]  )* \)  )*
               \)  )*  ,  (?: [\040\t] |  \(
                     (?:  [^\\\x80-\xff\n\015()]  |  \\ [^\x80-\xff]  |  \( (?:  [^\\\x80-\xff\n\015()]  |  \\ [^\x80-\xff]  )* \)  )*
               \)  )*  @  (?: [\040\t] |  \(
                     (?:  [^\\\x80-\xff\n\015()]  |  \\ [^\x80-\xff]  |  \( (?:  [^\\\x80-\xff\n\015()]  |  \\ [^\x80-\xff]  )* \)  )*
               \)  )*    (?:
  [^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff]+    # some number of atom characters...
  (?![^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff]) # ..not followed by something that could be part of an atom
 |   \[                         # [
                   (?: [^\\\x80-\xff\n\015\[\]] |  \\ [^\x80-\xff]  )*    #    stuff
                   \]                        #           ]
 )                           # initial subdomain
              (?:                                  #
                  (?: [\040\t] |  \(
                     (?:  [^\\\x80-\xff\n\015()]  |  \\ [^\x80-\xff]  |  \( (?:  [^\\\x80-\xff\n\015()]  |  \\ [^\x80-\xff]  )* \)  )*
               \)  )*  \.                        # if led by a period...
                  (?: [\040\t] |  \(
                     (?:  [^\\\x80-\xff\n\015()]  |  \\ [^\x80-\xff]  |  \( (?:  [^\\\x80-\xff\n\015()]  |  \\ [^\x80-\xff]  )* \)  )*
               \)  )*   (?:
  [^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff]+    # some number of atom characters...
  (?![^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff]) # ..not followed by something that could be part of an atom
 |   \[                         # [
                   (?: [^\\\x80-\xff\n\015\[\]] |  \\ [^\x80-\xff]  )*    #    stuff
                   \]                        #           ]
 )                     #   ...further okay
              )*
 )* # further okay, if led by comma
         :                                # closing colon
  (?: [\040\t] |  \(
                     (?:  [^\\\x80-\xff\n\015()]  |  \\ [^\x80-\xff]  |  \( (?:  [^\\\x80-\xff\n\015()]  |  \\ [^\x80-\xff]  )* \)  )*
               \)  )*  )?      #       optional route
                           (?:
  [^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff]+    # some number of atom characters...
  (?![^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff]) # ..not followed by something that could be part of an atom
 |
        " (?:                      # opening quote...
              [^\\\x80-\xff\n\015"]                #   Anything except backslash and quote
              |                     #    or
               \\ [^\x80-\xff]           #   Escaped something (something != CR)
                             )* "  # closing quote
 )                    # initial word
        (?:  (?: [\040\t] |  \(
                     (?:  [^\\\x80-\xff\n\015()]  |  \\ [^\x80-\xff]  |  \( (?:  [^\\\x80-\xff\n\015()]  |  \\ [^\x80-\xff]  )* \)  )*
               \)  )*  \.  (?: [\040\t] |  \(
                     (?:  [^\\\x80-\xff\n\015()]  |  \\ [^\x80-\xff]  |  \( (?:  [^\\\x80-\xff\n\015()]  |  \\ [^\x80-\xff]  )* \)  )*
               \)  )*   (?:
  [^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff]+    # some number of atom characters...
  (?![^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff]) # ..not followed by something that could be part of an atom
 |
        " (?:                      # opening quote...
              [^\\\x80-\xff\n\015"]                #   Anything except backslash and quote
              |                     #    or
               \\ [^\x80-\xff]           #   Escaped something (something != CR)
                             )* "  # closing quote
 )  )*        # further okay, if led by a period
  (?: [\040\t] |  \(
                     (?:  [^\\\x80-\xff\n\015()]  |  \\ [^\x80-\xff]  |  \( (?:  [^\\\x80-\xff\n\015()]  |  \\ [^\x80-\xff]  )* \)  )*
               \)  )*  @  (?: [\040\t] |  \(
                     (?:  [^\\\x80-\xff\n\015()]  |  \\ [^\x80-\xff]  |  \( (?:  [^\\\x80-\xff\n\015()]  |  \\ [^\x80-\xff]  )* \)  )*
               \)  )*    (?:
  [^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff]+    # some number of atom characters...
  (?![^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff]) # ..not followed by something that could be part of an atom
 |   \[                         # [
                   (?: [^\\\x80-\xff\n\015\[\]] |  \\ [^\x80-\xff]  )*    #    stuff
                   \]                        #           ]
 )                           # initial subdomain
              (?:                                  #
                  (?: [\040\t] |  \(
                     (?:  [^\\\x80-\xff\n\015()]  |  \\ [^\x80-\xff]  |  \( (?:  [^\\\x80-\xff\n\015()]  |  \\ [^\x80-\xff]  )* \)  )*
               \)  )*  \.                        # if led by a period...
                  (?: [\040\t] |  \(
                     (?:  [^\\\x80-\xff\n\015()]  |  \\ [^\x80-\xff]  |  \( (?:  [^\\\x80-\xff\n\015()]  |  \\ [^\x80-\xff]  )* \)  )*
               \)  )*   (?:
  [^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff]+    # some number of atom characters...
  (?![^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff]) # ..not followed by something that could be part of an atom
 |   \[                         # [
                   (?: [^\\\x80-\xff\n\015\[\]] |  \\ [^\x80-\xff]  )*    #    stuff
                   \]                        #           ]
 )                     #   ...further okay              )*
         #       address spec
                                     (?: [\040\t] |  \(
                     (?:  [^\\\x80-\xff\n\015()]  |  \\ [^\x80-\xff]  |  \( (?:  [^\\\x80-\xff\n\015()]  |  \\ [^\x80-\xff]  )* \)  )*
               \)  )*  >  #                  trailing >
  # name and address
                )  (?: [\040\t] |  \(
                     (?:  [^\\\x80-\xff\n\015()]  |  \\ [^\x80-\xff]  |  \( (?:  [^\\\x80-\xff\n\015()]  |  \\ [^\x80-\xff]  )* \)  )*
               \)  )*                       # optional trailing comment




More information about the luni mailing list