Home > Article > Web Front-end > Regular expression look-around concept and usage analysis
This article mainly introduces the concept and usage of regular expression lookaround, and specifically analyzes the concept, classification, usage and related precautions of lookaround. Friends in need can refer to the following
The examples in this article describe regular expressions Expressions look around concepts and usage. Share it with everyone for your reference, the details are as follows:
1. Look around is also called pre-search and zero-width assertion
2. Look around is divided into
##3. Look around only occupies the logical location and not the physical location
For example: matching files with a suffix name of txt
characters: file. txt, file2.exe regular \w(?=.exe) matches the string file2
4. How to look around
① Find phone numbers starting with 132
characters: My job My phone number starting with 132 is 13244444444 My phone number starting with 158 is 15822222222Regular(?=\d{11})132\d{8}
Matches 13244444444
Detailed explanation: First match the 132 and 158 numbers, and then match the 2 numbers according to the expression on the left
② Find the file with the suffix name txt
character file1. txt file2.exeregular
matches the string file2
(?<=exp) to determine the usage of reverse lookup① Get the file suffix characters of the specified file file1.text file2.exe fiel3.jpg
Regular(?<=[/\ w]+\.)\w+Match characters text exe jpg
The above is the detailed content of Regular expression look-around concept and usage analysis. For more information, please follow other related articles on the PHP Chinese website!