In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article is about what Flex regular expression rules are about. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
Flex regular expression (regularexpression) is to use a "string" to describe a feature, and then to verify that another "string" matches this feature. For example, if the expression "ab+" describes a feature as "a" and any "b", then "ab','abb','abbbbbbbbbb'" fits this feature.
Flex regular expressions can be used to:
(1) verify that the string matches the specified characteristics, such as verifying that it is a valid email address.
(2) it is more flexible and convenient to find a string from a long text that meets the specified characteristics than to find a fixed string.
(3) used to replace, more powerful than ordinary replacement.
Flex regular expressions are actually very simple to learn, and a few more abstract concepts are easy to understand. The reason why many people feel that the Flex regular expression is more complex, on the one hand, because most of the documents do not explain from shallow to deep, and the concept does not pay attention to the order, which brings difficulties to the reader's understanding; on the other hand, the documents that come with various engines generally have to introduce its unique features, but this part of the unique features is not the first thing we need to understand. Let's take a look at the Flex regular expression rules.
1.Flex regular expression rules
1.1 ordinary characters
Letters, numbers, Chinese characters, underscores, and punctuation marks that are not specifically defined in later chapters are all "ordinary characters". An ordinary character in an expression that matches the same character when it matches a string.
Example 1: the expression "c", when matching the string "abcde", the matching result is: successful; the matching content is: "c"; the matching position is: starts at 2 and ends at 3. (note: the subscript starts at 0 or 1, which may vary depending on the current programming language.)
Example 2: the expression "bcd", when matching the string "abcde", the matching result is: successful; the matching content is: "bcd"; the matching position is: starts at 1 and ends at 4.
Simple escape characters in 1.2Flex regular expressions
For some characters that are inconvenient to write, add "\" in front of them. In fact, we are already familiar with these characters.
Expressions can be matched
\ r,\ n
Represents carriage return and newline characters
\ t
Tab character
\\
Stands for "\" itself.
There are other punctuation marks that have special uses in later chapters, and the addition of "\" in front represents the symbol itself. For example: ^, $have a special meaning, if you want to match the "^" and "$" characters in the string, the expression needs to be written as "\ ^" and "\ $".
Expressions can be matched
\ ^
Match the ^ symbol itself
\ $
Match the $symbol itself
\.
Matches the decimal point itself.
The matching method of these escape characters is similar to that of "normal characters". It also matches the same character.
Example 1: the expression "\ $d". When matching the string "abc$de", the matching result is: successful; the matching content is: "$d"; the matching position is: starts at 3 and ends at 5.
1.3 Flex regular expressions that can match 'multiple characters'
Some representations in Flex regular expressions can match any one of the 'multiple characters'. For example, the expression "\ d" can match any number. Although you can match any of these characters, it can only be one, not multiple. It's like playing poker, big and small kings can replace any card, but only one card.
Expressions can be matched
\ d
Any number, any one of the 09s
\ w
Any letter or number or underscore, that is, any letter or number, that is, any letter or number or underscore, that is, any letter or number or underscore.
\ s
Any of the white space characters, including spaces, tabs, page feeds, etc.
.
The decimal point can match any character except the newline character (\ n).
Example 1: the expression "\ d\ d". When matching "abc123", the result of the match is: successful; the content of the match is: "12"; the position of the match is: starts at 3 and ends at 5.
Example 2: the expression "a.\ d". When matching "aaa100", the result of the match is: successful; the content of the match is "aa1"; the position of the match is: it starts at 1 and ends at 4.
1.4 Custom Flex regular expressions that can match 'multiple characters'
Use square brackets [] to contain a series of characters that can match any one of them. If you include a series of characters with [^], you can match any character other than one of them. By the same token, although you can match any one of them, it can only be one, not more than one.
Expressions can be matched
[ab5@]
Match "a" or "b" or "5" or "@"
[^ abc]
Match any character other than "a", "b", "c"
[fmurk]
Match any letter between "f" and "k"
[^ A-F0-3]
Match any character other than "A" ~ "F", "0" ~ "3"
Example 1: when the expression "[bcd] [bcd]" matches "abc123", the result of the match is: successful; the content of the match is "bc"; the position of the match is: it starts at 1 and ends at 3.
Example 2: when the expression "[^ abc]" matches "abc123", the result of the match is: successful; the content of the match is: "1"; the position of the match is: starts at 3 and ends at 4.
1.5 A special symbol that modifies the number of matches
The expressions mentioned in the previous section can only match once, whether they can match only one character or any one of multiple characters. If you use an expression plus a special symbol that modifies the number of matches, you can repeat the match without having to rewrite the expression.
The way to use it is to place "degree modifier" after "modified expression". For example, "[bcd] [bcd]" can be written as "[bcd] {2}".
Expression function
{n}
The expression is repeated n times, for example: "\ w {2}" equals "\ w\ w"; "a {5}" equals "aaaaa"
{m,n}
The expression should be repeated at least m times and n times at most. For example, "ba {1 baa 3}" can match "ba" or "baa" or "baaa".
{m,}
The expression is repeated at least m times, for example: "\ w\ d {2,}" can match "A12", "_ 456", "M12344".
?
Match the expression 0 or 1 times, which is equivalent to {0jin1}, for example: "a [cd]?" Can match "a", "ac", "ad"
+
The expression appears at least once, which is equivalent to {1,}. For example, "afigb" can match "ab", "aab", "aaab".
*
The expression does not appear or appears any number of times, which is equivalent to {0,}, for example: "\ ^ * b" can match "b" and "^ ^ b".
Example 1: the expression "\ d +\.?\ d *" when matching "Itcosts$12.5", the matching result is: successful; the matching content is "12.5"; the matching position is: starts at 10 and ends at 14.
Example 2: when the expression "go {2 go 8} gle" matches "Adsbygoooooogle", the result of the match is: successful; the content of the match is "goooooogle"; the position of the match is: starts at 7 and ends at 17.
Other special symbols in 1.6Flex regular expressions that represent abstract meaning
Some symbols represent the special meaning of abstraction in expressions:
Expression function
^
Matches the beginning of the string and does not match any characters
$
Matches the end of the string, not any characters
\ b
Matches a word boundary, that is, the position between a word and a space, and does not match any characters
The further textual description of ◆ is still quite abstract, so give examples to help you understand.
Example 1: when the expression "^ aaa" matches "xxxaaaxxx", the result is: failed. Because "^" requires a match with the beginning of the string, "^ aaa" can match only if "aaa" is at the beginning of the string, such as "aaaxxxxxx".
Example 2: when the expression "aaa$" matches "xxxaaaxxx", the matching result is: failed. Because "$" requires a match with the end of the string, "aaa$" can match only if "aaa" is at the end of the string, such as "xxxxxxaaa".
Example 3: the expression ".\ b." When matching "@ abc", the match result is: successful; the match content is "@ a"; the match position is: starts at 2 and ends at 4.
Further explanation: "\ b", similar to "^" and "$", does not match any characters, but it requires it to be on the left and right sides of the matching result, with a "\ w" range on one side and a non-"\ w" range on the other.
Example 4: when the expression "\ bend\ b" matches "weekend,endfor,end", the matching result is: successful; the matching content is "end"; the matching position is: starts at 15 and ends at 18.
◆ some symbols can affect the relationship between subexpressions within an Flex regular expression:
Expression function
| | OR relationship between left and right expressions, matching left or right () |
(1)。 When the number of matches is modified, the expression in parentheses can be modified as a whole
(2)。 When taking the matching result, the content matched by the expression in parentheses can be obtained separately.
Example 5: when the expression "Tom | Jack" matches the string "IsimmTomMagol heisJack", the matching result is: successful; the matching content is: "Tom"; the matching position is: starts at 4 and ends at 7. When matching the next one, the match result is: successful; the match content is "Jack"; when the match is reached, it starts at 15 and ends at 19.
Example 6: the expression "(go\ s *) +" matches "Let'sgogogo!" The match result is: successful; the match to the content is: "gogogo"; the match position is: starts at 6 and ends at 14.
Example 7: the expression "¥(\ d +\.?\ d*)" when matching "$10.9, ¥20.5", the result of the match is: success; the content of the match is "¥20.5"; the position of the match is: starts at 6 and ends at 10. Get the parenthesis range separately to match: "20.5".
Thank you for reading! This is the end of this article on "what are the rules of Flex regular expressions?". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to 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.