In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article will explain in detail about CentOS command summary of regular expression example analysis, Xiaobian think quite practical, so share to you as a reference, I hope you can read this article after harvest.
Regular expressions fall into two categories: basic regular expressions (BRE) and extended regular expressions (ERE).
Metacharacter meanings of basic regular expressions:
1、.:Matches any single character
2.[]: Matches a single character within a specified range
3.[^]: Matches a single character outside the specified range
* : Matches any number of characters preceding it.
5、\?:Matches 0 or 1 times before it
6,\+: matches its predecessor 1 or more times
7.\{m\}: exactly match m times
8.\{m,n\}: Match at least m times and at most n times
9、.*:Matches any character of any length
10,^: Line head anchor,
11,$: End of line anchor
12.\: Final anchoring (also\b)
14,^$: Match blank lines
15.\(\): Often used with\n(n is a number) to match the number of occurrences of a single or multiple character combination
Second, the metacharacter meaning of extended regular expressions:
1、.:Matches any single character
2.[]: Matches a single character within a specified range
3.[^]: Matches a single character outside the specified range
* : Matches any number of characters preceding it.
5、?:Matches 0 or 1 times before it
6,+: matches its predecessor 1 or more times
7.{m}: exactly match m times
8,{m,n}: match at least m times, at most n times
9、.*:Matches any character of any length
10,^: Line head anchor,
11,$: End of line anchor
12.\: Final anchoring (also\b)
14,^$: Match blank lines
15,(): often used with\n(n is a number) to match the number of occurrences of a single or multiple character combination
16、|: Match| Character before or after symbol
Third, the commands that can match regular expressions are: (here only grep command)
grep: grep matches lines of text with basic regular expressions.
Format: grep [OPTIONS] PATTERN [FILE...]
grep [OPTIONS] [-e PATTERN | -f FILE] [FILE...]
Options:
-E: Match using extended regular expressions (equivalent to egrep)
-F: equivalent to fgrep
-i: Case ignored when matching
-v: Display lines that do not match patterns
-o: Display only matched rows
-q: Silent mode
--color=auto: Highlight the matched character
IV. Examples:
1. Display lines ending in bash in/etc/passwd file;
2. Display two or three digits in the/etc/passwd file;
Display lines ending with 'LISTEN' followed by 0, 1, or more white space characters in the results of the 'netstat -tan' command
4. Add bash, testbash, basher, and nologin users (nologin user's shell is/sbin/nologin); then find the line in/etc/passwd where the user name is the same as the shell name;
5. Display the default shell and UID of the root, centos, or user1 user on the current system;
6. Find a line in the/etc/rc.d/init.d/functions file with a word (there can be an underscore in the middle of the word) followed by a set of parentheses
7. Use echo to output a path, and then egrep to find its path base name;
Further: use egrep to extract its directory name
8. Find the number between 1 and 255 in the ifconfig command execution result;
About "CentOS command summary of regular expression example analysis" This article is shared here, I hope the above content can be of some help to everyone, so that you can learn more knowledge, if you think the article is good, please share it to let more people see.
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.