preg_match_all("#4.*5#is","4xxx5xxx5",$re);
print_r($re);
output:
Array ( [0] => Array ( [0] => 4xxx5xxx5 ) ) 还有就是怎样能使第二种情况两个都匹配到。
---------------------------------------------
don't you think that will be a collision???

解决方案 »

  1.   

    还有就是怎样能使第二种情况两个都匹配到。
    我主要是需要应用到这里:
    网页源代码截取:
    key  <tr class="c"> <td ,...>asdasdasd <tr class="c"> <td ....>asdasdasd <tr class="c"> <td .....>asdasdasd
     
    标记中间有若干空格和换行。
    我需要匹配在key后的所有asdasdasd这里的内容,该怎么匹配?
    #key<tr class="c">\s*<[^>]*>\s*(\S*)\s*<#isU这样只能匹配第一行asdasdasd,有什么办法?
      

  2.   

    上面的正则应该是
    #key.*<tr class="c">\s*<[^>]*>\s*(\S*)\s*<#isU
    写错了,key后面的.*
      

  3.   

    preg_match_all("/(?=(4.*5))(?=(4.*?5))/is","4xxx5xxx5",$re);这样写可以同时匹配4xxx5和4xxx5xxx5
      

  4.   

    根据楼主的应用,实在没必要使用这种方式。
    试试:/<tr class="c">.*<td .*>(.*)</isU得到内容之后进行trim()来去除空格。
      

  5.   

    TO Gdj(陈水.智商只有129.非卖品) 
    如果不定项呢?需要匹配所有4到5之间的项有没有可能?
    TO zairwolfb(君子兰) 
    html里不只有这些项,一定要指定在key后面才行,否则会匹配到无关项。
      

  6.   

    如果不定项呢?需要匹配所有4到5之间的项有没有可能?
    那是没有可能的,除非你的项是固定的,
    匹配进行完一次之后只会进行下一次匹配,
    preg_match_all("#4.*5#is","4xxx5xxx5",$re);
    这样会匹配整个字符串,因为使用了贪婪匹配,
    贪婪是就是尽可能多的匹配!虽然4xxx5也符合,但没有4xxx5xxx5的串长,所以匹配了后者。
    二者只能选一,不能同时匹配!
      

  7.   

    ice_berg16(寻梦的稻草人) 
    帮忙看看我上面那个匹配网页源代码的有没有办法?貌似也没办法了。
      

  8.   

    key  <tr class="c"> <td ,...>asdasdasd <tr class="c"> <td ....>asdasdasd <tr class="c"> <td .....>asdasdasd
    ------------------------------I think the codes are incomplete and it is difficult to get the data you want.
      

  9.   

    就是要在关键字key后面的所有<tr class="c"> <td .....>后面的数据。
      

  10.   

    <tr class="c"> <td ....>asdasdasd (</td></tr>?????)<tr class="c"> <td .....>asdasdasd  (</td></tr>?????)
      

  11.   

    #key.*?(<tr class="c">\s*<[^>]*>\s*(\S*).+?)+<#is
      

  12.   

    Meteorlet(www.dictworld.com)
    这样的只能匹配最后一行。