Regular expression character meaning :


Match any character

/d 
accord with 0~9 Any numeric character

/D 
accord with 0~9 Characters other than

/s 
accord with /t,/n,/x0B,/f,/r Equal space character

/w 
accord with a~z,A~Z,0~9 Equal character , That is, numbers and letters match

/W 
accord with a~z,A~Z,0~9 Characters other than equal , That is to say, except for numbers and letters

for instance , If there is a string abcdebcadxbc, If used .bc For comparison , Matching substrings have abc,ebc,xbc
3 individual ; If using ..cd, The only substrings that match are abcd.

Character class example

[abc] 
accord with a,b or c

[^abc] 
accord with a or b or c Characters other than

[a-zA-Z] 
accord with a~z Or maybe A~Z Characters of

[a-d[m-p]] 
a~d Or maybe m~p, It can also be written as [a-dm-p]

[a-z&&[def]] 
a~z And it's d or e or f, The result is d or e or f Can match

[a-z&&[^bc]] 
a~z And it's not b or c

[a-z&&[^m-p]] 
a~z And it's not m~p

Specify beyond one character , You can also add “ Greedy Quantifiers ”(Greedy Quantifiers) To specify the number of possible occurrences of a character .

Examples of greedy quantifiers

X? 
X Once or not at all

X* 
X Zero or more times

X+ 
X One or more times

X{n} 
X Can appear n second

X{n,} 
X At least n second

X{n, m} 
X At least n second , But not more than m second

in addition , also Reluctant quantifiers,Possessive
quantifiers Designation of etc , Self reference java.util.regex.Pattern class API Description in document .

Java stay J2SE
1.4 Regular expression support later , You can API Documented java.util.regex.Pattern Find supported regular expression related information in class , Regular expressions can be applied to string matching , replace , Separation and other actions

Split instance :

        String IPString = "(.+)( Classification number :.+ )*";// Qualified regular expression
         if (IPS.matches(IPString)) {
            int start = IPS.indexOf(" Classification number :");
            int last = IPS.lastIndexOf(" ");
            s = IPS.substring(start + 4, last);
        }

Technology
©2019-2020 Toolsou All rights reserved,
Python Basic knowledge and notes Programmer Tanabata Valentine's Day confession code NOI2019 travels China's longest high speed rail officially opened ! The fastest way to finish the race 30.5 hour C Language programming to find a student's grade Software testing BUG describe ESP8266/ESP32 System : Optimize system startup time Unity Scene loading asynchronously ( Implementation of loading interface ) Baidu , Ali , Tencent's internal position level and salary structure , With job suggestions !PYTHON Summary of final review