I found that MySQL's regular expression is very "alternative"

zhaozj2021-02-16  109

I have encountered a problem today:

There is a set of integers to separate from small to large arranging, and now determine if a few numbers write MySQL regular expressions. For example: '| 12 | 14 | 16 | 20 | 120 | 130 | To determine if 12 16 is in this String.

The easiest way is '. * | 12 |. * | 16 |. *', But if it is '12' '14'? This is not. '. * | 12 |. * | 14 |. *' Does not match the string of the front, because they are adjacent, simple solution is to transform String with '||' separation, but this is a waste of space.

I saw a half-day manual found a very simple method '[[: <:]] 12 [[:>:]]. * [[: <:]] 14 [[:>:]].

[[: <:]] Refers to the start of the match, [[:>:]] match the number of words

MANUAL on:

[: <:]] [:>:]] The MARKERS Stand for Word Boundaries.................................................... . A Word Character IS An Alphaumeric Character in The alnum class or an underscore (_).

At the same time, 'has given a relatively general method.'. * | 12 | (. * |) * 14 |. * '

Regular expressions are indeed very magical. This is also a problem.

转载请注明原文地址:https://www.9cbs.com/read-10900.html

New Post(0)