Answer to the meaning of regular expression \w \d

小云云
Release: 2023-03-17 19:34:02
Original
1902 people have browsed it

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 special features. Symbols are completely incomprehensible. In fact, it’s just because you don’t understand regular expressions. Once you understand them, you will find that that’s it. There are actually not many related characters used in regular expressions, and they are not difficult to remember, let alone understand. The only difficulty is the readability after combining them. It is relatively poor and not easy to understand. This article aims to give everyone a basic understanding of regular expressions, so that everyone can understand simple regular expressions and write simple regular expressions to meet the needs of daily development. .

What is a regular expression

A regular expression is a special string pattern used to match a set of strings. It's like using a mold to make a product, and regular rules are this mold, defining a rule to match characters that match the rules.

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)

However, in actual use, it is found that this is not the case. It can also be said that it actually includes more than just ([0-9a -zA-Z_])These data,

The following is the test screenshot tool for editplus:

actually except ([0 -9a-zA-Z_]) also includes Greek letters, Russian letters, etc.;

So if you need to pay attention to the specific matching data when registering user information, you must not use it directly \w Done

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 environment

The above content is the regular expression\w The answer to the meaning of \d, I hope it can help everyone.

Related recommendations:

Understanding of \b in regular expressions

Summary of regular expressions commonly used in PHP forms

Summary of commonly used regular expressions

The above is the detailed content of Answer to the meaning of regular expression \w \d. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!