欢迎大家光临【无师自通-教程网】您的到来是我们的荣幸。本站提供photoshop教程,ps教程,flash教程,cad教程,网页制作教程,excel教程,asp教程,vb教程,3d教程,c语言教程,html教程,coreldraw教程,dreamweaver教程,java教程,3dmax教程 等各种教程为主题的内容和服务,相信您会在这里找到您所需要的东东。无师自通伴您一生-谢谢您的光临!!
网站地图 设为首页
简繁切换 加入收藏
栏目待定 留言本站
您现在的位置: 无师自通-教程网 >> WEB开发 >> PHP教程 >> 正则表达式 >> 教程正文

  没有公告

教程: PHP教程-正则表达式-关于php正则表达式的两点备注 更多...
教程: PHP教程-正则表达式-关于php正则表达式的两点备注


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
  
   /\*.*?\*/
  小结:
   ?与/U有类似功能,但同时出现彼此抵消
  
   如下:
      $a="asdf/*asdfaldsfasdf*/asfdasldf;kfldsj*/asfddsaf";
   $pattern="/\/\*.*?\*\//";
   //$pattern="/\/\*.*\*\//U";
   //$pattern="/\/\*.*?\*\//U";
   preg_match($pattern,$a,$match);
   print_r($match);
   ?>
  
   2.Assertions
   \w (?=;)
  
   matchesawordfollowedbyasemicolon,butdoesnotinclude
   thesemicoloninthematch,and
  
   foo(?!bar)
  
   matchesanyoccurrenceof"foo"thatisnotfollowedby
   "bar".Notethattheapparentlysimilarpattern
  
   小结:
   (?!)只前向判断匹配,如bar(?!foo),而(?!foo)bar没有意义
   (?



教程录入:admin    责任编辑:admin 
  • 上一篇教程:

  • 下一篇教程:
  • 【字体: 】【发表评论】【加入收藏】【告诉好友】【打印此文】【关闭窗口
     
     
     
     

    asp连接mysql数据库

    asp连接mysql数据库-2

    frontpage2000教程---制作主页
    免责声明!本站资料大部分来自于互联网,其版权归原作者或其他合法者所有.如内容涉及或侵犯了您的权益,请通知本人,我将尽快处理!.欢迎您的光临。
    辽ICP备07003958号
    无师自通,伴你一生-教程网