The connected characters in the regular expression match
After understanding the behavior of the character in the character class, the rewriting regular expression mode becomes very simple to match the character.
Lian character
In the character class (defined as or
), even the characters are considered ordinary characters, unless it appears between the other two characters. In this specific case, Lian character represents a character range.
[]
* Example: `[A-Za-Z0-9! $ [-]
TRN] **
In this mode, the character is not part of the range because it is not included between two characters. Therefore, it only matches the character itself. Add the characters to the character class
To match the connected characters and other characters, no need to rush it. Just include it in the character class, as shown below:
: matching the character.
: matching A, B, C, or connected characters.
[-]
: matching A, B, C, or connected characters. [abc-]
The above is the detailed content of How Do Regular Expressions Handle Hyphens in Character Classes?. For more information, please follow other related articles on the PHP Chinese website!