Regular expressions end with symbols such as $, \b, (?=…), (?!..), etc. Detailed introduction: 1. $, used to indicate the end of a string; 2. \b, used to match a position, not a specific character; 3. (?=…), used to match a position, not a specific character Characters, indicating that in the string after the current position, must be able to match..., but will not consume any characters; 4. (?!..), used to match a position, rather than specific characters, indicating that after the current position In the string, cannot match...etc.
# Operating system for this tutorial: Windows 10 system, Dell G3 computer.
What the regular expression ends with refers to how the end of a string is expressed in the regular expression. In regular expressions, we can use some special characters and symbols to indicate the end of a string.
Dollar sign ($): In regular expressions, the dollar sign is used to indicate the end of a string. For example, the regular expression "abc$" matches strings ending with "abc", such as "defabc", "xyzabc", but not "abcxyz".
Zero-width assertion (\b): Zero-width assertion is a special regular expression syntax used to match a position rather than a specific character. In regular expressions, \b represents a word boundary and can also be used to represent the end of a string. For example, the regular expression "abc\b" matches strings ending with "abc", such as "def abc", "xyz abc", but not "abc xyz".
Zero-width positive lookahead assertion ((?=...)): Zero-width positive lookahead assertion is a special regular expression syntax used to match a position, not specific characters. In regular expressions, (?=…) means that in the string after the current position, it must be possible to match … without consuming any characters. Therefore, we can use (?=$) to indicate the end of a string. For example, the regular expression "abc(?=$)" matches strings ending with "abc", such as "defabc", "xyzabc", but not "abcxyz".
Zero-width negative lookahead assertion ((?!..)): Zero-width negative lookahead assertion is a special regular expression syntax used to match a position, and Not specific characters. In regular expressions, (?!..) means that ... cannot be matched in the string after the current position. Therefore, we can use (?!.) to indicate the end of a string. For example, the regular expression "abc(?!.)" matches strings ending with "abc", such as "defabc", "xyzabc", but not "abcxyz".
It should be noted that the above methods can be selected and used according to specific needs. Sometimes, there may be some differences based on different regular expression engines and syntax rules. Therefore, when using regular expressions, it is best to consult relevant documentation and information to ensure correct use and understanding.
The above is the detailed content of What does a regular expression end with?. For more information, please follow other related articles on the PHP Chinese website!