In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces what the regular expressions in shell have, which can be used for reference by interested friends. I hope you can learn a lot after reading this article.
Classification of regular expressions
1. Basic regular expressions (Basic Regular Expression, also known as Basic RegEx or BREs)
2. Extended regular expressions (Extended Regular Expression, also known as Extended RegEx or EREs)
3. The regular expression of Perl (Perl Regular Expression is also called Perl RegEx for short PREs)
For details, you can refer to this article: https://www.jb51.net/tools/shell_regex.html
Regular expressions commonly used in shell
"^\ integer $" / / non-negative integer (positive integer + 0)
"^ [0-9] * [1-9] [0-9] * $" / / positive integer
"^ ((-\ d +) | (0 +) $" / / non-positive integer (negative integer + 0)
"^-[0-9] * [1-9] [0-9] * $" / / negative integer
"^ -?\ During $" / / Integer
"^\ d + (\.\ d +)? $" / / non-negative floating point number (positive floating point number + 0)
"^ (([0-9] +. [0-9] * [1-9] [0-9] *) | ([0-9] * [1-9] [0-9] *. [0-9] +) | ([0-9] * [1-9] [0-9] *)) $" / / positive floating point number
"^ ((-\ d + (\.\ d +)?) | (0 + (\ .0 +)?) $" / / non-positive floating point number (negative floating point number + 0)
"^ (- (([0-9] +. [0-9] * [1-9] [0-9] *) | ([0-9] * [1-9] [0-9] *. [0-9] +) | ([0-9] * [1-9] [0-9] *)) $" / / negative floating point number
"^ (-?\ d +) (\.\ d +)? $" / / floating point number
"^ [A-Za-z] + $" / / A string of 26 letters
"^ [Amurz] + $" / / A string of 26 English letters in uppercase
A string of 26 lowercase letters consisting of "^ [amurz] + $" / /
"^ [A-Za-z0-9] + $" / / A string of numbers and 26 letters
A string of numbers, 26 letters, or underscores
"^ [\ w -] + (\ .[\ w -] +) * @ [\ w -] + (\ .[\ w -] +) + $" / / email address
"^ [a-zA-z] +: / / (\ w+ (-\ w+) *) (\. (\ w+ (-\ w+) *)) * (\?\ S*)? $" / / url
/ ^ (d {2} | d {4})-(0 ([1-9] {1})) | (1 [1 | 2]))-([0-2] ([1-9] {1})) | (3 [0 | 1])) $/ year-month-day
/ ^ ((0 ([1-9] {1})) | (1 [1 | 2])) / ([0-2] ([1-9] {1})) | (3 [0 | 1])) / (d {2} | d {4}) $/ month / day / year
"^ ([wmere.] +) @ ([[0-9] {1Mague 3}. [0-9] {1pr 3}. [0-9] {1pr 3}.) | (([w -] +.)) ([a-zA-Z] {2jue 4} | [0-9] {1Mague 3}) (]?) $" / / Emil
/ ^ ((\ +? [0-9] {2jue 4}\-[0-9] {3pm 4}\ -) | ([0-9] {3pm 4}\ -))? ([0-9] {7pr 8}) (\-[0-9] +)? $/ / phone number
"^ (d {1 1dd 2} | 1dd | 2 [0-4] d | 25 [0-5]). (d {1 IP 2} | 1dd | 2 [0-4] d | 25 [0-5]). (d {1 recorder 2} | 1dd | 2 [0-4] d | 25 [0-5]). (d {1pm 2} | 1dd | 2 [0-4] d | 25 [0-5])
Regular expressions that match Chinese characters: [\ u4e00 -\ u9fa5]
Match double-byte characters (including Chinese characters): [^\ X00 -\ xff]
Regular expression that matches blank lines:\ n [\ s |] *\ r
Regular expression that matches the HTML tag: /. * | /
Regular expression that matches leading and trailing spaces: (^\ s*) | (\ sblank $)
The regular expression that matches the Email address:\ W + ([- +.]\ w +) * @\ w + ([-.]\ w +) *.\ w + ([-.]\ w +) *
The regular expression that matches the URL URL: ^ [a-zA-z] +: / / (\\ w+ (-\\ w+) *) (\. (\\ w+ (-\\ w+) *)) * (\?\ S*)? $
Whether the matching account is legal (5-16 bytes are allowed at the beginning of the letter, and alphanumeric underscores are allowed): ^ [a-zA-Z] [a-zA-Z0-9 _] {4j 15} $
Match domestic phone number: (\ d {3}-|\ d {4} -)? (\ d {8} |\ d {7})?
Match Tencent QQ number: ^ [1-9] * [1-9] [0-9] * $
Metacharacters and their behavior in the context of regular expressions:
\ Mark the next character as a special character, or a literal character, or a backward reference, or an octal escape character.
^ matches the starting position of the input string. If the Multiline property of the RegExp object is set, ^ also matches the position after'\ n'or'\ r'.
$matches the end of the input string. If the Multiline property of the RegExp object is set, $also matches the position before'\ n'or'\ r'.
* matches the previous subexpression zero or more times.
+ matches the previous subexpression one or more times. + is equivalent to {1,}.
? Matches the previous subexpression zero or once. ? It is equivalent to {0jue 1}.
{n} n is a non-negative integer that matches a determined n times.
{n,} n is a non-negative integer that matches at least n times.
{n ·m} m} m and n are non-negative integers, where n)?
28. The IP address in the extracted information: (\ d +)\. (\ d +)
29. The Chinese mobile phone number in the extracted information: (86) * 0mm 13\ d {9}
30. The Chinese fixed phone number in the extracted information: (\ (\ d {3pr 4}\) |\ d {3pr 4}-|\ s)?\ d {8}
31. Chinese phone numbers (including mobile and landline phones) in the extracted information: (\ (\ d {3pr 4}\) |\ d {3pr 4}-|\ s)?\ d {7P 14}
32. The postcode of China in the extracted information: [1-9] {1} (\ d+) {5}
33. Extract the floating point number (that is, decimal) in the information: (-?\ d *)\.?\ d +
34. Extract any number from the information: (-?\ d *) (\.\ d +)?
35. IP: (\ d +)\. (\ d +)
36. Area code: / ^ 0\ d {2jue 3} $/
37. Tencent QQ: ^ [1-9] * [1-9] [0-9] * $
38. Account number (beginning with letters, 5-16 bytes allowed, alphanumeric underscores are allowed): ^ [a-zA-Z] [a-zA-Z0-9 _] {4jue 15} $
39. Chinese, English, numbers and underscores: ^ [\ u4e00 -\ u9fa5_a-zA-Z0-9] + $
Thank you for reading this article carefully. I hope the article "what are the regular expressions in shell" shared by the editor will be helpful to you? at the same time, I also hope you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!
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.