Home  >  Article  >  Web Front-end  >  Regular expression look-around concept and usage analysis

Regular expression look-around concept and usage analysis

巴扎黑
巴扎黑Original
2017-06-16 10:28:521872browse

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

                                                                                                                                                               

## (?! Exp)

# (? & LT; Exp)

##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

(?=exp) 2 ways to use certain order lookup

① Find phone numbers starting with 132

characters: My job My phone number starting with 132 is 13244444444 My phone number starting with 158 is 15822222222

Regular(?=\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

\w+(?=.exe)

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn