In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Network Security >
Share
Shulou(Shulou.com)05/31 Report--
This article will explain in detail the example analysis of regular expression keywords for you. The editor thinks it is very practical, so I share it for you as a reference. I hope you can get something after reading this article.
Submode
When using regular expressions, we often use () to enclose a part, which is called a subpattern.
There are two cases of submodes: Capturing and Non-Capturing.
Capturing refers to getting a match or capturing a match, which means that the system will save all sub-pattern matching results behind the scenes for us to find or replace. Such as the use of backward references
Non-Capturing refers to non-acquisition matching or non-capture matching, at this time, the system will not save the matching results of sub-patterns, and the matching of sub-patterns is mostly used as a constraint, such as forward pre-check, reverse pre-check, positive pre-check and so on.
Backward reference (also called backreference)
Use "\ number" to represent the match of one of the previous subpatterns.
We use regular expressions, which are used in many scenarios to find and replace. When looking up, a backward reference is used to represent a subpattern, the syntax is "\ numeric" and in substitution, the syntax is "$numeric". The number indicates that the previous subpattern is referenced here. You can refer to named capture grouping.
Pre-check, positive, reverse, positive and negative pre-check
Including forward pre-check, reverse pre-check, subdivided and each has positive pre-check and negative pre-check.
Features:
All pre-checks are non-acquisition matches and do not consume characters. That is, after a match occurs, the next matching search begins immediately after the matching character, rather than after containing the pre-checked character.
Positive direction
Match whether the thing that follows is equal to / not equal to
Reverse
Match whether the thing that follows is equal to / not equal to
sure
Match whether the thing that follows / follows is equal to
Negation
Does the match follow / precede something not equal to
Positive positive pre-check
(? = pattern) the string that follows the prediction must match with pattern
Let's start with a simple example:
Match words with ing in English sentences, but don't ing. Varcon= "coming soon,going gogogo" varreg = /\ b [\ w] + (? = ing\ b) / ing / match the word with ing, but not ing. Note: if you do not add\ b after ing, similar to goingabc will also match. Console.log (con.match (reg))
The result matches to ["com", "go"]. First match the word boundary\ b, then + match the previous several times or once, and then go to this forward preview. (? = ing) means to probe backward first to see if there is an ing.
If so, match the previous one; if not, move the cursor back one bit to continue probing.
This process is forward pre-checking: prejudge to a certain value. Then the matching does not contain this element, which is called ing.
The official word is that the match does not need to be obtained for later use, but is a non-capture match.
Positive negative pre-check
(?! pattern) the string that follows the prediction must not match the pattern
Reverse positive pre-check
(? Reverse pre-check, the pattern length must be fixed, that is, there can be no pattern such as *. Such characters make the length of the pattern match not fixed; however, there is no such requirement in the forward direction.
Example
Consider such an application scenario: for a large number, such as 35689412, Western countries are used to three digits of one order of magnitude, separated by commas, to make it easy to see the size at a glance, that is, 35689412. So now there is a pile of numbers, please replace it with a regular expression and replace it with a format such as 35689412.
Topic analysis: that is, from right to left, every three numbers, if there is a number in front of it, add a comma in front. That is, find these specific locations and add "," to that location.
Varnumber = "82359123650916359816359"; varregex = / (? This is the end of the article on "sample analysis of regular expression keywords". 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, please 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.