First, let’s briefly introduce regular expressions:
When writing programs or web pages that process strings, there is often a need to find strings that match certain complex rules. Regular expressions are tools used to describe these rules. In other words, regular expressions are codes that record text rules.
Let’s take a look at what the messy characters in regular expressions mean:
1. Commonly used metacharacters
. Matches any character except newlines
\w matches letters or numbers or underscores or Chinese characters
\s matches any whitespace character
\d matches digits
\b matches the beginning or end of a word
^ Matches the beginning of a string
$ Matches the end of the string
Then let’s try to understand:
\bhello\b actually searches for the word hello - first the beginning of a word (\b), then the string hello, and finally the end of the word (\b).
010-\d\d\d\d\d\d\d\d For example, Beijing's landline phone number - first 010-, then 8 digits (\d).
^\d{18}$ For example, the ID number - first the string starts (^), then the 18-digit number (\d), and finally the string ends ($).
All resources on this website are contributed and published by netizens, or reprinted by major download sites. Please check the integrity of the software yourself! All resources on this website are for learning and reference only. Please do not use them for commercial purposes, otherwise you will be responsible for all consequences incurred! If there is any infringement, please contact us to delete and remove it. Contact information: admin@php.cn