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 > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces "explaining linux about regular expression grep". In daily operation, I believe many people have doubts in explaining linux about regular expression grep. Xiaobian consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful to answer the doubts of "explaining linux about regular expression grep". Next, please follow the editor to study!
A regular expression (Regular Expression) is a pattern used to describe a set of string characteristics and to match a specific string. Through special characters + ordinary characters to describe the pattern, so as to achieve the purpose of text matching tool. Similar to the common apocalypse of finding people in life, "search matching" is carried out by describing the characteristics of a person.
Nowadays, regular rules have been widely used by us and are now integrated into various text editors / text processing tools.
Application scenario * * Verification: * * user name and password verification is performed when the form is submitted. * * find: * * quickly extract specified content from a large amount of information. In a batch of url, find the specified url replacement: do a regular matching search for the text in the specified format, and then make a specific replacement after finding it, (vim text replacement, etc.)
In many technical fields (for example, natural language processing, data storage, etc.), regular expressions can easily extract the information we want, so this part is essential to constitute the basic element character class quantity qualifier bit qualifier special symbol.
1. Character class:
An example of a character description. Match any character abc. Can match abcd, abc0, etc. [] match any character [012a] a can match 0a, 1a, 2a-indicate character range in parentheses such as [0-9] can match any number ^ placed in front of [] means match any character except the character in parentheses [^ ab] c can match 1c, dc But cannot match ac, bc [[: xxx:]] grep tool predefined named character classes [[: digit:]] can match a number, [: alpha:] match a character, [[: lower:]] match any lowercase letter, etc.
Application:
Grep uses the-- color option to mark the matching string in red. Echo $? can be used in Linux. To print the exit code executed by the previous command, 0 indicates successful execution and 1 indicates failure.
The experiments are as follows:
Note: use. The default is greedy matching, which is related to the following regular matching, which will be discussed later.
two。 Quantity qualifier:
An example of a character description? Match the unit immediately before it (a number or character in front of it) 0 or 1 if you match the decimal, use 0\.? [0-9] to match 0.1, 0.2, 0.3, etc. There is a special symbol in the rule, so you need to escape with\ (later) + match the unit immediately in front of it 1 or more times [a-zA-Z0-9. -] + @ [a-zA-Z0-9. -] +\ .com match an email address * match the unit in front of it 0 or more times [0-9] [0-9] * match at least one digit It is equivalent to [0-9] + {N} to match exactly with the unit in front of it N times [0-9] {3} to match the number between 000 and 999
{N,} matching follows the unit in front of it at least N times [0-9] {3,} matches three digits or more {, M} matches the unit in front of it at most M times [0-9] {, 1} is equivalent to [0-9]? {N M} match closely follows the unit in front of it: IP address: [0-9] {1jue 3}\. [0-9] {1jue 3}\. [0-9] {1JEI 3}\. [0-9] {1pc3}
Application:
3. Location qualifier:
Character description: for example, ^ matches the position at the beginning of a line. World matches only the position at the end of a line at the beginning of a line, starting at the end of a line; $matches the position at the end of a line. Sign, ^ $match blank line match word end position p > match sleep, leap, etc., do not match parent, sleepy\ b match word start position, end position such as\ borld match world, aorld,\ borld\ b match only orld\ B match non-word beginning and end position such as\ Bat\ B match battery, do not match attend, hat, etc. Words that begin and end with the string "at"
Note: where\ b is used to define whether there are words in the target string that begin with the specified string, which we call the word boundary. \ B call it a non-word boundary.
Application:
4. Special symbols:
Character description examples\ escape characters, ordinary characters escape to special characters, special characters escape to ordinary characters
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.