Greedy match: Matches the string as long as possible when matching matches, by default, greedy match
String pattern1 = @ "A.*c"; Greedy match regex regex = new Regex (PATTERN1); regex. Match ("Abcabc"); Return "ABCABC"
non-greedy match : matches the shortest possible string, using the? To represent a non-greedy match when the match is met
String pattern1 = @ "A.*?c"; Non-greedy match Regex regex = new Regex (PATTERN1); regex. Match ("Abcabc"); Return "ABC"
Several commonly used non-greedy matching pattern
*? Repeat any number of times, but with as few repetitions as possible +? Repeat 1 or more times, but repeat as little as possible?? Repeat 0 or 1 times, but repeat {n,m} as little as possible. Repeat N to M times, but repeat {n,} as little as possible. Repeat more than n times, but repeat as little as possible
650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M00/77/DB/wKioL1ZvzI3xJ9TTAAJ4eW9k7oo890.png "title=" Regular expressions. png "alt=" Wkiol1zvzi3xj9ttaaj4ew9k7oo890.png "/>
This article is from the "bit accumulation" blog, please be sure to keep this source http://tianxingzhe.blog.51cto.com/3390077/1723247
Greedy match and non-greedy match