Home > Article > Web Front-end > Detailed explanation of the use of \w\d in regular expressions
This time I will bring you a detailed explanation of the use of \w\d in regular expressions. What are the precautions when using \w\d in regular expressions? The following are Let’s take a look at practical cases.
I believe many people know about regular expressions, but many people’s first impression is that it is difficult to learn, because at first glance, they feel that there are no rules at all, and they are all a bunch of various Such special symbols are completely incomprehensible. In fact, it’s just because you don’t understand regular rules. Once you understand them, you will find that that’s it. There are actually not many related characters used in regular rules, and they are not difficult to remember, let alone understand. The only difficulty is the combination. After getting started, the readability is relatively poor and it is not easy to understand. The purpose of this article is to let everyone have a basic understanding of regular expressions, understand simple regular expressions, and write simple regular expressions to meet daily needs. Just meet the needs during development.What is a regular expression
Regular expression is a special After consulting many related regular descriptions, I found that the definition of \w refers to containing uppercase and lowercase letters, numbers and underscores, which is equivalent to([0-9a-zA-Z])
(Based on the classic regular expression 30-minute introductory tutorial)
([0-9a -zA-Z_])These data,
([0 -9a-zA-Z_]) also includes Greek letters, Russian letters, etc.;
PS: Let’s look at the regular expression \w \s \d \b
. Matches any character except newline characters \w Matches letters or numbers or underscores or Chinese characters, which is equivalent to '[^A-Za-z0-9_]'. \s Matches any whitespace character\d Matches digits\b Matches the beginning or end of a word^ Matches the beginning of a string$ Match the end of the string\wWhether Chinese characters can be matched depends on your operating system and your application environmentI believe you have mastered it after reading the case in this article For more exciting methods, please pay attention to other related articles on the php Chinese website! Recommended reading:Methods of regular expression matching URL, phone number, mobile phone, and email address
JS regular replacement Search keyword highlighting effect
The above is the detailed content of Detailed explanation of the use of \w\d in regular expressions. For more information, please follow other related articles on the PHP Chinese website!