正则表达式问号的四种用法详解

网络编程 发布日期:2024/10/11 浏览次数:1

正在浏览:正则表达式问号的四种用法详解

原文符号

因为"htmlcode">

string pattern1 = @"a.*c";  // greedy match 
Regex regex = new Regex(pattern1);
regex.Match("abcabc"); // return "abcabc"

非贪婪匹配

在满足匹配时,匹配尽可能短的字符串,使用"htmlcode">

string pattern1 = @"a.*";  // non-greedy match 
Regex regex = new Regex(pattern1);
regex.Match("abcabc"); // return "abc"

几个常用的非贪婪匹配Pattern

*"htmlcode">

while(<>){
  if(/("Fred wants a $1\n" ;
  }
}