In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-21 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces "what are the grammatical rules of web regular expressions". In daily operation, I believe many people have doubts about what the grammatical rules of web regular expressions are. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful for you to answer the doubts about "what are the grammatical rules of web regular expressions?" Next, please follow the editor to study!
Line locators (^ and $)
The line locator is used to describe the boundary of the string. "^" indicates the beginning of the line; "$" represents the end of the line. Such as:
^ tm: this expression indicates that the starting position of the string tm to match is the line header, such as tm equal Tomorrow Moon.
Tm$: this expression indicates that the position of the string tm to match is at the end of the line, and the Tomorrow Moon equal tm matches.
If the string to be matched can appear in any part of the string, it can be written directly as: tm
Word delimiters (\ b,\ B)
The word delimiter\ b indicates that the string you are looking for is a complete word. Such as:\ btm\ b
There is also a capital\ B, which means the opposite of\ b. The string it matches cannot be a complete word, but is part of another word or string. Such as:\ Btm\ B
3. Character class ([])
Regular expressions are case-sensitive, and use the square bracket expression "[]" if you want to ignore case. As long as the matching character appears in square brackets, it indicates that the match is successful. But be careful: a square bracket can only match one character.
4. Select a character (|)
Another way to achieve the above matching pattern is to use the selection character (|). The character can be understood as "or", as in the above example, it can also be written as? (T | t) (M | m), which means that the expression begins with the letter T or t, followed by the letter M or m.
The difference between using "[]" and using "|" is that "[]" can only match a single character, while "|" can match a string of any length. If you are not afraid of trouble, the above example can also be written as: TM | tm | Tm | tM
5. Hyphen (-)
The naming rule for variables is that they can only start with letters and underscores. But in this way, if you want to use a regular expression to match the first letter of a variable name, write it as?: [a _ rep _ b _ p _ r _ d … A _
This is undoubtedly very troublesome, and regular expressions provide a hyphen "-" to solve this problem. A hyphen can represent a range of characters. As in the above example, it can be written as: [a-zA-Z]
6. Exclude characters ([^])
The above example matches variables that match the naming convention. Now, in turn, matching variables that do not conform to the naming convention, the regular expression provides the "^" character. This metacharacter appears earlier, indicating the beginning of the line. Here it will be put in square brackets to indicate the meaning of exclusion.
For example: [^ a-zA-Z], this expression matches a variable name that does not begin with a letter and an underscore.
Qualifier (* + {nrecom})
For repeated letters or strings, you can use qualifiers to match.
8. Dot character (.)
The dot character (.) can match any character other than the newline character.
Note: it is any character except the newline character. Such as matching words that begin with s, end with t and contain a letter in the middle.
The format is as follows: ^ s. Tasking. The matching words include: sat, set, sit, etc.
To give another example, match a word with the first letter r, the third letter s, and the last letter t. The regular expression that matches the word is: ^ r.s.roomt$
9. Escape character (\)
The shift characters (\) in regular expressions are more or less the same as those in PHP, which turn special characters (such as ".", "?", "\", and so on) into normal characters. To give an example of an IP address, use a regular expression to match an IP address in a format such as 127.0.0.1. If you use dot characters directly, the format is: [0-9] {1jue 3} (. [0-9] {1jue 3}) {3}
This is obviously wrong, because "." Can match any character. At this point, not only IP like 127.0.0.1, but also strings like 127101011 will be matched. So I'm using "." You need to use the escape character (\). After modification, the above regular expression format is:? [0-9] {1Magne3} (\. [0-9] {1p3}) {3}
10. Backslash (\)
In addition to being able to escape characters, backslashes have other functions. Backslashes can display some non-printable characters, and you can also specify predefined character sets. Backslashes also have the function of defining assertions.
11. Parenthesis characters (())
The first function of parenthesis characters is to change the scope of qualifiers, such as "|", "*", "^", and so on. Let's look at the following expression.
(thir | four) th, this expression means to match the words thirth or fourth. If you don't use parentheses, it becomes the matching words thir and fourth.
The second function of parentheses is to group, that is, subexpressions. For example, (\. [0-9] {1pm 3}) {3}, it is a repetitive operation on the grouping (\. [0-9] {1jue 3}). The reverse references that you will learn later are directly related to grouping.
XII. Reverse reference
XIII. Pattern modifier
The function of the pattern modifier is to set the mode. That is, how regular expressions should be interpreted and applied.
At this point, the study of "what are the grammatical rules of web regular expressions" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
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.