In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces how to verify the regular expression of email address in Linux, which is very detailed and has certain reference value. Friends who are interested must read it!
The specification for email addresses comes from RFC 5322. There is a website called emailregex.com that lists regular expressions that validate email addresses in various programming languages, many of which are complex that I have never seen before-I mean, how much the programmers of this site have been hurt by email validation!
In fact, in a production environment, it is generally not necessary for such complex regular expressions to be 99.99% correct. In general, in terms of execution efficiency and test coverage, you only need a simple version:
/ ^ [A-Z0-9.9% salary -] + @ [A-Z0-9.-] +\. [Amurz] {2jue 4} $/ I
So let's take a look at these more rigorous and complex regular expressions:
Verify the general regular expression of the email address (conforms to the RFC 5322 standard) (?: [a-z0-9 regular expressions% verify email strings? ^ _ `{|} ~ -] + (?:\. [a-z0-9 registered email% matching strings? ^ _ {|} ~ -] +) * | (: [\ x01 -\ x08\ 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\ x21a\ x53 -\ x7f] |\ [\ x01e -\ x09\ x0b\ X0c\ x0e-\ x7f])
Because different languages have different support for regular expressions, syntax differences, and coverage, regular expressions vary from language to language:
Python
This is a simple version:
R "(^ [a-zA-Z0-9 colors -] + @ [a-zA-Z0-9 -] +\. [a-zA-Z0-9 color.] + $)" Javascript
This is a little complicated:
/ ^ [- a-z0-9 benchmark% ^ & * _ = +} {\'?] + (\. [- a-z0-9 resume% ^ & * _ = +} {\\'?] +) * @ ([a-z0-9 _] [- a-z0-9 _] * (\. [- a-z0-9 _] +) *\. (aero | arpa | biz | com | coop | gov | info | int | mil | name | net | org | pro | travel | mobi | [ACPZ] [aanthz]) | ([0-9] {1je3}\. [0-9] {1cane3}. }\. [0-9] {1 A-Za-z0 3}\. [0-9] {1 A-Za-z 3}) (: [0-9] {1 mine 5})? $/ iSwift [A-Z0-9a A-Za-z0.% colors -] + @ [A-Za-z0-9 -] +\. [A-Za-z] {2jue 6} PHP
This version of PHP is more complex and has more coverage:
/ ^ (?) (: (?:\ 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] +) | (?: [\ x01 -\ x08\ x0B\ x0C\ x0E -\ x1F\ x21\ x23 -\ x5D -\ x7F]) (?:\ x5C [\ x00 -\ x7F]) *\ x22)) (?:\. (?): [\ x21\ x23 -\ x2A\ x2B \ x2D\ x2F -\ x39\ x3D\ x3F\ x5e -\ x7e] +) | (?:\ x22 (?: [\ x01 -\ x08\ x0B\ x0C\ x0E -\ x1F\ x21\ x23 -\ x5B\ x5D -\ x7F]) * @ (: (?: (?) }) (?: xn--)? [a-z0-9] + (?:-[a-z0-9] +) *\.) {1126}) {1 } (?: (: [a-z0-9] *) | (?: (: xn--) [a-z0-9] +)) (?:-[a-z0-9] +) *) | (?:\ [: IPv6: (?: [a-f0-9] {1Currentin 4} (:: [a-f0-9] {1pm 4}) {7}) | -f0-9] [:\]]) {7 }) (?: [a-f0-9] {1Magne 4} (?:: [a-f0-9] {1pr 4}) {0Magne 5}): (: [a-f0-9] {1pr 4} (?:: [a-f0-9] {1pr 4}) {0pr 5}) | (: (: IPv6: (?): [a-f0-9] {1jue 4} (?:: [a-f0-9] {1pm 4}) {5}:) ?: (?! (?:. * [a-f0-9]:) {5 }) (?: [a-f0-9] {1Mague 4} (?:: [a-f0-9] {1Mague 4})): (: [a-f0-9] {1Power4} (?:: [a-f0-9] {1pr 4}) {0jue 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}) $/ iDPerl / Ruby
Dissatisfied with the versions of PHP, Perl and Ruby, you can be more rigorous:
(?: (?:\ r\ n)? [\ t]) * (: [^ () @,;:\ ".\ [\]\ 000 -\ 031] + (?:\ r\ n)? [\ t]) + |\ Z | (? = [\ [" () @ :\\ ".\ [])) |" (?: [^\ "\ r\\] |\\. | (?: (?:\ r\ n)? [\ t])) *" (?: (?:\ r\ n)? [\ t]) * (?:\. (: (?:\ r\ n)? [\ t]) * (: [^ () @) :\\ ".\ [\]\ 000 -\ 031] + (?:\ r\ n)? [\ t]) + |\ Z | (? = [\ [" () @ :\\ ".\ [[]])) |" (?: [^\ "\ r\\] |\. | (?: (?:\ r\ n)? [\ t])) *" (?: (?:\ r\ n)? [\ t])) * @ (?: (?:\ r\ n)? [\ t]) * (?: [^ () @) :\\ ".\ [\]\ 000 -\ 031] + (?:\ r\ n)? [\ t]) + |\ Z | (? = [\ [" () @ :\\ ".\ []) |\ [([^\ [\]\ r\] |\\.) *\] (?: (?:\ r\ n)? [\ t]) (?:\. (: (?:\ r\ n)? [\ t]) * (?: [^ () @ :\\ ".\ [\]\ 000 -\ 031] + (?:\ r\ n)? [\ t]) + |\ Z | (? = [\ [" () @,;:\ ". [])) |\ [([^ [\]\ r\] |\\.) *] (?: (?:\ r\ n)? [[\ t]) * | (?: [^ () @ @) :\\ ".\ [\]\ 000 -\ 031] + (?:\ r\ n)? [\ t]) + |\ Z | (? = [\ [" () @ :\\ ".\ [[]])) |" (?: [^\ "\ r\] |\. | (?: (?:\ r\ n)? [\ t])) *" (?: (?:\ r\ n)? [\ t]) *) * (?: (?:\ r\ n)? [\ t]) *) | (?: [^ () @ @) :\\ ".\ [\]\ 000 -\ 031] + (?:\ r\ n)? [\ t]) + |\ Z | (? = [\ [" () @ :\\ ".\ [[]])) |" (?: [^\ "\ r\] |\. | (?: (?:\ r\ n)? [\ t])) *" (?: (?:\ r\ n)? [\ t]) *: (?: (?:\ r\ n)? [\ t]) * (?: [^ () @ @) :\\ ".\ [\]\ 000 -\ 031] + (?:\ r\ n)? [\ t]) + |\ Z | (? = [\ [" () @ :\\ ".\ [])) |" (?: [^\ "\ r\\] |\\. | (?: (?:\ r\ n)? [\ t])) *" (?: (?:\ r\ n)? [\ t]) * (?:\. (: (?:\ r\ n)? [\ t]) * (: [^ () @) :\\ ".\ [\]\ 000 -\ 031] + (?:\ r\ n)? [\ t]) + |\ Z | (? = [\ [" () @ :\\ ".\ [[]])) |" (?: [^\ "\ r\\] |\. | (?: (?:\ r\ n)? [\ t])) *" (?: (?:\ r\ n)? [\ t])) * @ (?: (?:\ r\ n)? [\ t]) * (?: [^ () @) :\\ ".\ [\]\ 000 -\ 031] + (?:\ r\ n)? [\ t]) + |\ Z | (? = [\ [" () @ :\\ ".\ []) |\ [([^\ [\]\ r\] |\\.) *\] (?: (?:\ r\ n)? [\ t]) (?:\. (: (?:\ r\ n)? [\ t]) * (?: [^ () @ :\\ ".\ [\]\ 000 -\ 031] + (?:\ r\ n)? [\ t]) + |\ Z | (? = [\ [" () @,;:\ ". [])) |\ [([^ [\]\ r\] |\\.) *] (?: (?:\ r\ n)? [[\ t]) * | (?: [^ () @ @) :\\ ".\ [\]\ 000 -\ 031] + (?:\ r\ n)? [\ t]) + |\ Z | (? = [\ [" () @ :\\ ".\ [[]])) |" (?: [^\ "\ r\] |\. | (?: (?:\ r\ n)? [\ t])) *" (?: (?:\ r\ n)? [\ t]) *) * (?: (?:\ r\ n)? [\ t]) *) (?:,\ s* (?: [^ () @) :\\ ".\ [\]\ 000 -\ 031] + (?:\ r\ n)? [\ t]) + |\ Z | (? = [\ [" () @ :\\ ".\ [])) |" (?: [^\ "\ r\\] |\\. | (?: (?:\ r\ n)? [\ t])) *" (?: (?:\ r\ n)? [\ t]) * (?:\. (: (?:\ r\ n)? [\ t]) * (: [^ () @) :\\ ".\ [\]\ 000 -\ 031] + (?:\ r\ n)? [\ t]) + |\ Z | (? = [\ [" () @ :\\ ".\ [[]])) |" (?: [^\ "\ r\\] |\. | (?: (?:\ r\ n)? [\ t])) *" (?: (?:\ r\ n)? [\ t])) * @ (?: (?:\ r\ n)? [\ t]) * (?: [^ () @) :\\ ".\ [\]\ 000 -\ 031] + (?:\ r\ n)? [\ t]) + |\ Z | (? = [\ [" () @ :\\ ".\ []) |\ [([^\ [\]\ r\] |\\.) *\] (?: (?:\ r\ n)? [\ t]) (?:\. (: (?:\ r\ n)? [\ t]) * (?: [^ () @ :\\ ".\ [\]\ 000 -\ 031] + (?:\ r\ n)? [\ t]) + |\ Z | (? = [\ [" () @,;:\ ". [])) |\ [([^ [\]\ r\] |\\.) *] (?: (?:\ r\ n)? [[\ t]) * | (?: [^ () @ @) :\\ ".\ [\]\ 000 -\ 031] + (?:\ r\ n)? [\ t]) + |\ Z | (? = [\ [" () @ :\\ ".\ [[]])) |" (?: [^\ "\ r\] |\. | (?: (?:\ r\ n)? [\ t])) *" (?: (?:\ r\ n)? [\ t]) *) * (: (?:\ r\ n)? [\ t]) *) *);\ sPerl 5.10 and later
The above version, um, can I say the Book of Heaven? Anyway, I have no idea of interpreting it. Of course, the new version of the Perl language also has a more readable version (are you serious? )
/ (? (DEFINE) (? (? & mailbox) | (? & group)) (? (& name_addr) | (? & addr_spec)) (? (? & display_name)? (? & angle_addr)) (? (? & CFWS)?
< (?&addr_spec) >(? & CFWS)) (? (& display_name): (?: (& mailbox_list) | (? & CFWS))? (CFWS)) (? (phrase)) (? (? & mailbox) (?) (? & mailbox)) *) (? (? & local_part)\ @ (? & domain)) (? (? & dot_atom) | (? & quoted_string)) (? (& dot_atom) | (? & domain_literal)) (? (& CFWS)?\ [(?: (? & FWS)? (? & dcontent)) * (? & FWS)?\] (? & CFWS)?) ? & dtext) | (? & quoted_pair)) (? (? & NO_WS_CTL) | [\ x21 -\ x5a\ x5e -\ x7e]) (? (& ALPHA) | (? & DIGIT) | [! #\ $% &'* +-/ =? ^ `{|} ~]) (? (? & CFWS)? (? & atext) + (? & CFWS)?) (? (? & CFWS)? (? & dot_atom_text) (& CFWS)) (? (& atext) + (?:\. (? & atext) +) *) (? [\ x01 -\ x09\ x0b\ x0c\ x0e -\ x7f]) (?\ (? & text) (? (& NO_WS_CTL) | [\ x21\ x23 -\ x5b\ x5d -\ x7e]) (? (? & qtext) | (? & quoted_pair)) (? (? & CFWS)? (? & DQUOTE) (?: (? & FWS)? (? & qcontent) * (? & FWS)? (? & DQUOTE) (? & CFWS)) (? (? & atom) | (? & quoted_string)) (? (? & word) +) # Folding white space (? (?: (? & WSP) * (? & CRLF))? (? & WSP) +) (? (? & NO_WS_CTL) | [\ x21 -\ x27\ x2a -\ x5b\ x5d -\ x7e]) Ctext) | (? & quoted_pair) | (? & comment)) (?\ ((?: (? & FWS)? (? & ccontent)) * (? & FWS)?\)) (? (: (? & FWS)? (? & comment)) * (?: (: (? & FWS)? (? & comment) # No whitespace control (? [?\ x01 -\ X08\ x0b\ X0c\ X0e-\ X1f\ x7f]) [A-Za-z]) (? [0-9]) (?\ x0d\ x0a) (? ") (? [\ x20\ x09])) (? & address) / xRuby (simple version)
Ruby says they actually have a simple version:
/\ A ([\ w+\ -].) + @ [amurz\ d\ -] + (\ .[ a-z] +) *. [amerz] +\ z/i.NET
Who doesn't have such a version--. NET said:
^\ w+ ([- +.']\ w+) * @\ w+ ([-.]\ w+) *\.\ w+ ([-.]\ w+) * $grep command
Use the grep command to find the e-mail address in the file. I don't think you can write a regular expression with several lines.
$grep-E-o "\ b [A-Za-z0-9.9% filename.txtSQL Server -] + @ [A-Za-z0-9.-] +\. [A-Za-z] {2jue 6}\ b" filename.txtSQL Server
Regular expressions can also be used in SQL Server, but this code snippet should come from a production environment, so it also takes care of those who write the email address incorrectly:
Select email from table_name where patindex ('% [&', ";! + =\ / ()]%', email) > 0-- Invalid characters or patindex ('[@.-_]%', email) > 0-- Valid but cannot be starting character or patindex ('% [@. -]', email) > 0-- Valid but cannot be ending character or email not like'% @%.%-- Must contain at least one @ and one. Or email like'%..%'--Cannot have two periods in a row or email like'% @% @%'--Cannot have two @ anywhere or email like'%. @%'or email like'% @.%'--Cannot have @ and. Next to each other or email like'%. Cm' or email like'% .co'--Camaroon or Colombia? Typos. Or email like'% .or'or email like'% .ne'--Missing last letterOracle PL/SQL
Isn't this a little lazy? Especially after those "complex" regular expressions:
SELECT email FROM table_nameWHERE REGEXP_LIKE (email,'[A-Z0-9.percent% -] + @ [A-Z0-9.percent% -] +\. [Amurz] {2jue 4}'); MySQL
Well, it looks like * is just as lazy:
SELECT * FROM `users`WHERE `email` NOT REGEXP'^ ^ [A-Z0-9.9% -] + @ [A-Z0-9.-] +\. [Amurz] {2pm 4} $'. This is all the content of the article "how to implement regular expressions for verifying email addresses in Linux". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.