Analysis on the use of PHP regular expression character sets. What is the PHP regular expression character set? How can the use of PHP regular expression character sets be helpful for our development and use? What is the form of PHP regular expression character set and the use of the regular PHP regular expression character set? How can the use of PHP regular expression character sets be helpful for our development and use? What is the form of PHP regular expression character set and the rules for use? Let's introduce them one by one,
Related concepts of PHP regular expression character set:
In INTERNET programs, regular expressions are usually used to verify user input. After a user submits a FORM, it is not enough to determine whether the entered phone number, address, EMAIL address, and credit card number are valid. Therefore, we need to use a more free way to describe the mode we want. it is a character cluster. To create a character cluster that represents all vowels, place all vowels in a square bracket.
PHP regular expression character set format:
- [AaEeIiOoUu]
This mode matches any vowel character, but can only represent one character. The font size can be used to indicate the range of a character, for example:
- [A-z]// Match all lowercase letters
- A-Z// Match all uppercase letters
- [A-zA-Z]// Match all letters
- [0-9]// Match all numbers
- [0-9.-]// Match all numbers, periods, and minus signs
- [Frtn]// Match all white characters
Similarly, these are only one character, which is very important. If you want to match a string consisting of a lowercase letter and a digit, such as "z2", "t6", or "g7 ", if it is not "ab2", "r2d3", or "b52", use this mode:
- ^[a-z][0-9]$
Although [a-z] represents the range of 26 letters, it can only match strings with lowercase letters with the first character.
Use of PHP regular expression character set:
^ Indicates the start of a string, but it has another meaning. When ^ is used in square brackets, it indicates "not" or "excluded", which is often used to remove a character. In the preceding example, the first character must not be a number:
- ^[^0-9][0-9]$
This pattern matches "& 5", "g7", and "-2", but does not match "12", "66. The following are examples of how to exclude specific characters:
- [^ A-z]// All characters except lowercase letters
- [^/^]// All characters except "/" and "^"
- [^"'] // Except double quotation marks (") And all characters except single quotes (')
The special character "." (Point, period) is used to represent all characters except the "new line" in a regular expression. Therefore, the pattern "^. 5 $" matches any two-character string that ends with a number 5 and starts with another non-New Line character. Mode "." can match any string, except empty strings and strings containing only one "new line.
The PHP regular expression character set will be introduced here. I hope that will help you understand and use the PHP regular expression character set.
Why? How can the use of PHP regular expression character sets be helpful for our development and use? PHP regular expression character set format and usage rules...