When I used regular expressions, I discovered a very strange phenomenon, as follows:
[--\ˇ]
< /p>
[_-\ˇ]
< /p>
[=-\ˇ]
< /p>
That is, the first one cannot match letters, the second one can match letters, and the third one can match letters and slashes
I just want to replace these special characters when they appear in the string. I didn’t expect that even the letters will be replaced. I know that I can use other writing methods to achieve this requirement, but I just don’t know why it is so weird to write this way. Great God Let us explain this rule.
Holy shit, there are still these, it’s so hard to write a regular regex
[+-~]
[i-~]
[--~]
[_-~]
[=-~]
...
If you are interested, try matching it with hello w\o\r\l\d
.
我想大声告诉你2017-05-16 13:09:23
First of all, the first example should not be a legal regular, so there will be no result.
The regular expressions in the following two examples are the most basic [a-z]
syntax, which means matching all characters from one character to another character encoding.
In the two examples, the starting character is _
、=
, 终止字符都是全角符号 ˇ
.
Full-width symbol encoding is greater than all ASCII encodings. All are matched when matching AscII encoding. Without thinking too much, let’s check the ASCII encoding of the starting character.
ASCII encoding: /
< 0-9
< =
< A-Z
< <
_
< a-z
So, [=-ˇ]
能匹配大写字母、反斜杠、小写字母,[_-ˇ]
can only match lowercase letters, neither can match forward slashes and numbers.
Secondly, it is better not to write such a strange regular expression, as it is difficult to maintain.