Home  >  Article  >  Web Front-end  >  Regular expressions look around concepts and usage_regular expressions

Regular expressions look around concepts and usage_regular expressions

微波
微波Original
2017-06-28 13:35:041160browse

This article mainly introduces regular expressionsthe concept and usage of lookaround. It specifically analyzes the concept, classification, usage and related notes of lookaround. Friends in need can refer to it. Next

The examples in this article describe the concept and usage of regular expression look-around. 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)Definitely look around in reverse order

                                                                                                                        Look around in reverse order

3. Look around only occupies the logical location and not the physical location

For example: matching files with the suffix name txt

Characters: file.txt, file2.exe Regular \w(?=.exe)

Matches

string file2

4. How to use look around

(?=exp) Two ways to use look around in certain order

① Find phone numbers starting with 132

Characters: My job number is 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 suffix name as txt file

characters file1.txt file2.exe

regular

\w+(?=.exe) matches the string file2

(?<=exp) Determine the usage of reverse lookup

① Get the file suffix

character of the specified file file1.text file2.exe fiel3.jpg

Regular (?<=[/\w]+\.)\w+

matching characters text exe jpg

PS: Here are 2 more special Convenient regular expression tool for your reference:

JavaScript

Regular expression online testing tool:

http://tools.jb51.net/regex/javascript

Regular expression online generation tool: http://tools.jb51 .net/regex/create_reg

The above is the detailed content of Regular expressions look around concepts and usage_regular expressions. 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