日期:2013-08-14  浏览次数:20384 次

severaltipsaboutRegularExpressions
  1.processfor"greedy"
  Bydefault,thequantifiersare"greedy",thatis,they
  matchasmuchaspossible(uptothemaximumnumberofper-
  mittedtimes),withoutcausingtherestofthepatternto
  fail.Theclassicexampleofwherethisgivesproblemsisin
  tryingtomatchcommentsinCprograms.Theseappearbetween
  thesequences/*and*/andwithinthesequence,individual
  *and/charactersmayappear.AnattempttomatchCcom-
  mentsbyapplyingthepattern
  
  /\*.*\*/
  
  tothestring
  
  /*firstcommand*/notcomment/*secondcomment*/
  
  fails,becauseitmatchestheentirestringduetothe
  greedinessofthe.*item.
  
  However,ifaquantifierisfollowedbyaquestionmark,
  thenitceasestobegreedy,andinsteadmatchestheminimum
  numberoftimespossible,sothepattern
  
  /\*.*?\*/