0

I have a Low Replace tag that uses a regex to target links:

{exp:low_replace
    find='<a[^>]*href=QUOTE(.+)QUOTE[^>]*(.*)>(.*)<\/a>'
    replace='<a href=QUOTE$1QUOTE$2 style=QUOTEcolor: #007766; text-decoration: underline;QUOTE><span style=QUOTEcolor: #007766;QUOTE>$3</span></a>'
    regex='yes'
}
    <a href="http://google.com" target="_blank">Search on Google</a> <a href="http://bing.com" title="Search on Bing">or Bing</a>.
{/exp:low_replace}

But if the links are on the same line, Low Replace will only replace the last one. If I separate the links with a line break, like this:

<a href="http://google.com" target="_blank">Search on Google</a> 
<a href="http://bing.com" title="Search on Bing">or Bing</a>.

then Low Replace works as expected.

I'm certain this is some problem with my regex, can anyone offer some insight?

4

You'll need to make the any-character match not greedy using a ?:

<a[^>]*?href=QUOTE(.+?)QUOTE[^>]*?(.*?)>(.*?)<\/a>

That'll probably help.

4
  • Thanks for the fast reply! I just tried making the changes you suggested, but it didn't work :/ – kmgdev Oct 7 '13 at 16:52
  • 1
    Added another ? just before the href. Try again? – Low Oct 7 '13 at 17:58
  • Nope, still doesn't work. – kmgdev Oct 7 '13 at 20:03
  • Aaand another one after the +. Surely now it works? – Low Oct 7 '13 at 21:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.