This paper illustrates the concept and usage of regular expression looping. Share for your reference, as follows:
1. Looking around is also called pre-search and zero-width assertion.
2. Circumferential vision is further divided into
(?=exp)Affirmative sequential glance
(?<=exp)Positive Reverse Sequence Looking around
(?!exp)Negative Sequence Looking around
(?<exp)Negative Reverse Sequence Looking around
3. Looking around occupies only logical position, not physical position.
For example: matching files with suffix name TXT
Characters: file. txt, file2. exe rules
\w(?=.exe)Match string File2
4. Usage of Looking around
(?= exp) Two uses of affirmative sequential looping
1. Finding the phone number is 132.
Character: My work number is 132. My telephone number is 13244444. My 158 is 15822222.
Explanation: Match 132 and 158 numbers first, then match the number 2 according to the expression on the left.
(2) Find files with suffix name TXT
Character file1.txt file2.exe
\w+(?=.exe)Match string File2
(?<=exp) Affirms the use of reverse looping
(1) Get the file suffix of the specified file
Character file1.text file2.exe fiel3.jpg
(?<=[/\w]+\.)\w+Matching character text exe jpg
PS: Here are two very convenient regular expression tools for your reference.
Online Generation Tool for Regular Expressions:
I hope that this paper will be helpful for regular expression learning.