首页 > 开发 > PHP > 正文

关于php正则表达式的两点备注

2024-05-04 22:57:54
字体:
来源:转载
供稿:网友
  • 本文来源于网页设计爱好者web开发社区http://www.html.org.cn收集整理,欢迎访问。
  • 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
      
      //*.*?/*/
    发表评论 共有条评论
    用户名: 密码:
    验证码: 匿名发表