In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-14 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article will explain in detail what is the use of regular expressions and grep tools. Xiaobian thinks it is quite practical, so share it with you as a reference. I hope you can gain something after reading this article.
Regular expressions are also called regular expressions and conventional expressions. Regular Expression: A regular expression uses a single string to describe and match a sequence of characters that conform to a syntactic rule. In many text editors, regular expressions are often used to retrieve and replace text that matches a pattern. Many programming languages (PHP, C#, Java, C++, Objective-c, Swift, VB, Javascript, Ruby, and Python) support string manipulation with regular expressions. The concept of regular expressions was first popularized by Unix tools such as sed and grep.
Simply put: regular expressions can be understood as describing certain rules to achieve certain pattern matching, such rules are called regular expressions. Regular expression is a logical formula for string operation, that is, some specific characters defined in advance and combinations of these specific characters are used to form a "regular string". This "regular string" is used to express a filtering logic for string.
Given a regular expression and another string, we can achieve the following:
1. Whether a given string matches the filtering logic of a regular expression (called a "match");
2. Regular expressions can be used to get the specific part we want from a string.
The characteristics of regular expressions are:
1. Flexibility, logic and functionality are very strong;
2. Complex control of strings can be achieved quickly and in a very simple way.
3. It's hard to understand for someone new.
Regular expressions consist of some ordinary characters and some metacharacters. Common characters include upper and lower case letters and numbers, while metacharacters have special meanings. eg: In the simplest case, a regular expression looks like an ordinary search string. For example, the regular expression "testing" does not contain any metacharacters and matches strings such as "testing" and "testing123," but not "Testing." (Not included)
A regular expression consists of three parts: a character class (describing the characteristics of the characters contained in a string), a quantity qualifier (the number of corresponding characters in the string), and a position qualifier (the characteristics of the positions of characters in the string).
Specify some special syntax to represent character classes, quantity qualifiers, and positional relationships, and then combine these special syntax with ordinary characters to represent a pattern, which is a regular expression.
Note: Note that regular expression parameters are enclosed in single quotes, because many special characters used in regular expressions also have special meanings in the Shell (for example\). Only by enclosing them in single quotes can we ensure that these characters are passed to the grep command intact and will not be interpreted by the Shell.
grep: Text filtering tool. It can search text using regular expressions and print matching lines. grep stands for Global Regular Expression Print, which represents the version of a global regular expression that is available to all users. Regular expressions are used in grep to find strings that match a pattern. Grep looks for lines that contain a pattern.
egrep is equivalent to grep -E, indicating Extended regular expression syntax. Grep regular expressions have Basic and Extended specifications. The difference between the two is mainly in the analysis of the special characters in the above picture.
For Basic mode, the character?+ {}|() should be interpreted as ordinary characters, to express the above special meaning needs to add\escape.
For Extend mode, the character?+ {}|() should be interpreted as a special character, to express the ordinary literal meaning needs to add\escape.
Specific examples:
IP address legitimacy discrimination
Final grep matches legal IP expression
grep option test
About "regular expressions and grep tools what to use" 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.