The basic pattern matches everything from the basic beginning. Pattern is the most basic element of a regular expression. they are a set of characters that describe character strings. The mode can be very simple. it is composed of common strings and can be very complex. special characters are often used to indicate characters in a range, repeated occurrences, or context. For example:
Basic mode matching
Everything starts from the most basic. Pattern is the most basic element of a regular expression. they are a set of characters that describe character strings. The mode can be very simple. it is composed of common strings and can be very complex. special characters are often used to indicate characters in a range, repeated occurrences, or context. For example:
^ Once
This mode contains a special character ^, indicating that this mode only matches strings starting with once. For example, this pattern matches the string "once upon a time" and does not match "There once was a man from NewYork. Like a ^ symbol, $ is used to match strings ending in a given pattern.
Bucket $
This mode matches "Who kept all of this cash in a bucket" and does not match "buckets. When both the character ^ and $ are used, it indicates exact match (the string is the same as the pattern ). For example:
^ Bucket $
Only match the string "bucket ". If a mode does not include ^ 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 indicate 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 a new line, and \ r is used to represent a carriage return. Other special symbols can be used in front with a backslash. for example, the backslash itself is represented by \, the period is represented by \., and so on.
The above is the detailed content of the regular expression matching rule. For more information, see other related articles in the first PHP community!