0

I have a little problem and don't find any solution :(

I try to replace this text :

<table cellspacing="0" cellpadding="0" width="100%" border="0">
    <tbody>
        <tr>
            <td width="25%"><a href="http://www.test.com/myfile.pdf?min" target="_blank">Menus 18 €</a></div></td>
            <td width="25%"><a href="http://www.test.com/myfile.pdf?min" target="_blank">Menus 24 et 26 €</a></div></td>
            <td width="25%"><a href="http://www.test.com/myfile.pdf?min" target="_blank">Menus 30 et 37 € </a></div></td>
            <td width="25%"><a href="http://www.test.com/myfile.pdf?min">La Carte détaillée&nbsp;<br>
            (Entrées - Viandes - Poissons)</a></td>
        </tr>
    </tbody>
</table>

with this regex :

/<a.*?href=\"(.+.pdf\?min)\".*?>(.*?)<\/a>/s

But instead of returning each link replaced by ok, it replaces only one occurrence. I thought the greedy quantifier .*? could do the trick but not...

To try it : https://regex101.com/r/iF7dV0/1

Thanks in advance!

Peter

zb226
  • 9,586
  • 6
  • 49
  • 79
peter
  • 3
  • 1
  • As you're new to StackOverflow, let me share this [classic post](http://stackoverflow.com/a/1732454/989121) with you. TLDNR: do not use regexes for html work. – georg Mar 10 '15 at 11:00

2 Answers2

0

use the global g modifier, to get every occurence

dvhh
  • 4,724
  • 27
  • 33
0

Just turn the inbetween .+ to .+?, so that it would do a non-greedy match or otherwise it would greedily match many characters as much as possible.

<a.*?href=\"(.+?.pdf\?min)\".*?>(.*?)<\/a>
               ^

DEMO

Avinash Raj
  • 172,303
  • 28
  • 230
  • 274