HuntePHP continues * NIX's consistent tradition and fully supports regular expression processing. Regular expressions provide an advanced but not intuitive method for string matching and processing. Anyone who has used regular expressions in PERL knows that the function of regular expressions is not Hunte.
PHP continues * NIX's consistent tradition, fully supporting regular expression processing. Regular expressions provide an advanced but not intuitive method for string matching and processing. Friends who have used regular expressions in PERL know that regular expressions are very powerful, but they are not so easy to learn.
For example:
^. @. \... $
This effective but hard-to-understand code is enough to make some programmers have a headache (I am) or let them give up applying regular expressions. Trust that after reading this tutorial, you can understand the meaning of this code.
Basic mode matching
Everything starts from the very beginning. Pattern is the most basic element of a regular expression. they are a group of characters that describe character strings. The mode can be very simple, composed of common strings, and can be very complex. special characters are often used to represent characters in a category, repeatedly present, or express high and low texts. For example:
^ Once
This mode contains a special character ^, indicating that this mode only matches strings starting with once. For example, this mode matches the string 'Once upon a Time' and does not match 'There once was a man from NewYork. Like the beginning of a ^ symbol, the $ symbol is used to match strings that end with a given pattern.
Bucket $
This mode matches 'who kept all of this cash in a bucket' and does not match 'buckets. Characters ^ and $ are exactly matched when they are applied at the same time (the same string and pattern ). For example:
^ Bucket $
Only the string 'bucket' is matched '. If a mode does not contain ^ and $, it matches any string containing this mode. Example: mode
Once
And string
There once was a man from NewYork
Who kept all of his cash in a bucket.
Is matched.
In this mode, letters (o-n-c-e) are literal characters, that is, they represent the letter itself, and numbers are the same. Escape sequences are used for other slightly complex characters, such as punctuation marks and white characters (spaces and tabs. All escape sequences start with a backslash. The escape sequence of the tab is \ t. So if we want to check whether a string starts with a tab character, we can use this mode:
^ \ T
Similarly, \ n is used to represent the "New Line" and \ r is used to represent the carriage return. Other special symbols can be used in front with a backslash, for example, the backslash itself is represented by \, the ending periods, periods, and hyphens.
Character cluster
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.
So 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 vowel characters, place all vowel characters in a square bracket:
[AaEeIiOoUu]
This mode matches any vowel character, but can only represent one character. The font size can be used to represent the category of a character, for example:
[A-z] // match all lowercase letters
[A-Z] // match all uppercase letters
[A-zA-Z] // match all letters