当前位置:开发者网络 >> 技术教程 >> PHP教程 >> 数据库相关 >> 内容
精彩推荐
分类最新教程
分类热点教程
  
关于php正则表达式的两点备注
作者:未知
日期:2004-09-22
人气:
投稿:snow(转贴)
来源:未知
字体:
收藏:加入浏览器收藏
以下正文:
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
  
  /\*.*?\*/
相关文章: