ohdanax.blogg.se

Mysql regular expression not greedy
Mysql regular expression not greedy





mysql regular expression not greedy

In the example above, match to the first aAfter, start matching. That is to say, once the match is found to meet the requirements, the match will be successful immediately and will not continue to match (unless there is g, turn on the next set of matches)Īs you can see, the non greedy pattern identifier is very regular, that is, the greedy pattern identifier is followed by a ? When the regular expression is used to match, it will match as little content as possible The first match is a, and then match the next character aThe and regular do not match, so the match fails, indexMove to 1, then the match is successful ac, continue to match down, because it is greedy mode, try to match as many results as possible until the last one meets the requirements bSo far, the matching result is acbacb Non greedy matching pattern

mysql regular expression not greedy

*Because it’s a greedy pattern, it will match back until the last one satisfies the condition bSo far, the matching result is aacbacb When matching, if the above identifier is encountered, it means greedy matching and will match as much as possible When the regular expression is used to match, it will match as many content as possible This applies to the following greedy and non greedy patterns (and takes precedence over them), so keep in mind Quick understanding of greedy mode and non greedy mode Greedy match pattern Then it will continue to match until the match is complete, that is to say index=0Does not change until the match is complete (if a match fails and cannot be backtracked, indexWill continue to move down) The first match has the highest priorityįor example, the first matching character is a, it is assumed that no matching failure occurs in the subsequent matching.If the regular match is followed by gThis keyword will continue to start the next set of matches (but not in this case g, so there is only one set of results).Next match the next character b, just and /ab/Match, so this match was successful, and returned ab, index=1.indexMove to next, from 1Now, it’s a rematch a.Next match the next character a, but due to aaand /ab/No match, so this match failed.initial index=0, matched to character a.To quickly understand the regular matching rules, try to understand the above examples first Introduction to matching rules var str='aabcab' Quick understanding of greedy mode and non greedy mode.When we understand the difference between greed and non greed, we can step by step according to the examples outline Greedy pattern and non greedy pattern are important characteristics of regular matching







Mysql regular expression not greedy