Regular expressions are universal, common to all languages, and are crucial in all languages. I believe that many programmers will encounter this problem when they first start learning regular expressions. They see a bunch of messy symbols, their heads are full, and they feel like they have no way to start. Let me explain to you the most commonly used regular expressions. , simple wildcard \d \w.
1. The definition of \w generally refers to containing uppercase and lowercase letters, numbers and underscores, which is equivalent to ([0-9a-zA-Z]) .
But in actual use, it is found that this is not the case. It can also be said that it does not only include ([0-9a-zA-Z_]) these data.
The following is a screenshot I took while doing the test. My editing tool is editplus:
Actually except ([0-9a-zA -Z_]) also includes Greek letters, Russian letters, etc.
So, if we want to specifically match the data when registering user information, we must not use \w directly. We need to do more matching, so that our code can be considered rigorous.
2. \d is basically used to match numbers. There is no need to understand its meaning too much. When we usually write regular expressions, we must think more carefully, so as to ensure the rigor of our code. Not prone to BUG.
Several other commonly used methods of regular expressions are written below for your reference:
. Matches anything except newline characters character.
\s matches any whitespace character.
\b Matches the beginning or end of a word.
^ Matches the beginning marker of a string.
$ Matches the end marker of the string.
I would like to make it clear here that \w can also match Chinese characters, but this depends on your operating system and environment. I will not go into details. I will wait for everyone to do it. When matching Chinese characters, you will know it after a little understanding. It is not difficult.
I would like to thank the php Chinese website for providing such a good platform. If you have any questions, you can reply in the comment area below!
The above is the detailed content of What is the php regular expression \w\d?. For more information, please follow other related articles on the PHP Chinese website!