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 /\*.*?\*/ |
正在阅读:关于php正则表达式的两点备注关于php正则表达式的两点备注
2004-02-14 09:33
出处:PConline
责任编辑:linjixiong
键盘也能翻页,试试“← →”键