In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article will explain in detail how to achieve zero-width assertions in php regular expressions. The editor thinks it is very practical, so I share it with you as a reference. I hope you can get something after reading this article.
Concept
Zero-width assertions, defined this way in most places, are used to find things before or after certain content (but not including them), that is, they are like\ b ^ $\
< >Such anchoring is used to specify a location that should satisfy certain conditions (that is, assertions), so they are also called zero-width assertions. My understanding is to do a match search before or after a string with a defined location. So zero-width assertion, the execution process is divided into two cases, if it is a positive assertion, it should be like this. The first step is to judge whether the assertion is true (that is, whether certain conditions are met). If the conditions are met, then proceed to the next step to find a match. If it is a reverse assertion, the first step is to match in the order of regular expressions. The second step is to meet the reverse endorsement and judge whether it satisfies the negative endorsement.
Positive advance assertion
What is a positive antecedent assertion is to look for a match before the corresponding position of the string, using (? = exp) to match the position before the exp.
Example
$str= "abcgwcab"; $parent='/bc (? = gw) /'; $str=preg_match ($parent,$str,$match); var_dump ($match); / * * output result: int 1array (size=1) 0 = > string 'bc' (length=2) * /
Parsing: first look up the gw position in the string "abcgwcab", assert it to be true, and then match the bc. If you write the regular expression as $parent='/bc (? = gw) ca/';, the match will not succeed.
Anti-antecedent assertion
What is an anti-antecedent assertion? using (?! exp) matching is not followed by exp.
Example:
$str= "abcgwcab"; $parent='/bc (?! ww) gw/';$str=preg_match ($parent,$str,$match); var_dump ($str); var_dump ($match); / * * output: int 1array (size=1) 0 = > string 'bcgw' (length=4) * /
Parsing: first determine whether the string contains bc, then determine that it is not followed by ww, and finally match gw. You can see that before and after the reverse assertion, you can add other matching conditions.
Make a positive and posterior assertion
What is a positive and post assertion, that is, to find a match after the corresponding position of the string, (? String 'ca' (length=2) * /
Parsing: the first step is to find out whether the character "abcgwcab" contains gw, return the result as true, and then proceed to the second step to find out if there is a ca after the gw.
Make an assertion later
What is an anti-post-assertion that uses (?
Str= "abcgwcab"; $parent='/ (?
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.