Get the App
SLTechnology News&Howtos  ›  Development  › 

What are the special characters of PHP regular expressions

Shulou Source: shulou.com Published: 2022-06-02 19:37:20 09月28日 Update

Editor to share with you what are the special characters of PHP regular expressions. I hope you will get something after reading this article. Let's discuss it together.

The PHP regular expression special characters "[]" and "\", so what are they? What is the specific operation? Why they are special characters, is there anything special in the process of using them? Let's take a look at the introduction.

Two other important special characters are "[]". They can match characters that have appeared in "[]", such as "/ [az] /" can match a single character "a" or "z"; if you change the above expression to this "/ [a murz] /", you can match any single lowercase letter, such as "a", "b", and so on.

About the PHP regular expression special character "[]":

If "^" appears in "[]", it means that this expression does not match the characters that appear in "[]", such as "/ [^ amurz] /" does not match any lowercase letters! And the regular expression gives several default values for "[]":

◆ [: alpha:]: matches any letter

◆ [: alnum:]: matches any letter and number

◆ [: digit:]: matches any number

◆ [: space:]: matches the space character

◆ [: upper:]: matches any capital letter

◆ [: lower:]: matches any lowercase letter

◆ [: punct:]: matches any punctuation mark

◆ [: xdigit:]: matches any hexadecimal number

About the PHP regular expression special character "\":

The following special characters are represented by the escape symbol "\" as follows:

◆ s: matches a single space character

◆ S: used to match all characters except a single space character.

◆ d: used to match numbers from 0 to 9, equivalent to "/ [0-9] /".

◆ w: used to match letters, numbers, or underscore characters, equivalent to "/ [a-zA-Z0-9] /".

◆ W: used to match all characters that do not match w, equivalent to "/ [^ a-zA-Z0-9] /".

◆ D: used to match any non-decimal numeric character.

.◆: used to match all characters except newline characters, if modified by the modifier "s", "." Can represent any character.

After reading this article, I believe you have a certain understanding of "what are the special characters of PHP regular expressions". If you want to know more about it, you are welcome to follow the industry information channel. Thank you for reading!

Tags: Character special expression letter regular number single representative lowercase space space character symbol article escape binary important underscore two in the reason Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno macOS OPPO Reno Xiaomi MariaDB Apple