regexyahoo-pipes

regular expression: find and replace each match


I need to change the elements that surround some contents in a string, leaving the content as is. I'm doing it with a regular expression, but when I replace using the positional parameter ($1), it only uses the first match.

For example, if I have this string:

<strong>I want</strong> to change <i>this</i> text, 
but <u>I can't</u>. <div class="question">Why?</div>.

I want to change it to:

<strong>I want</strong> to change <i>this</i> text, 
but <u>I can't</u>. <div class="question">Why?</div>.

But I can only get this:

<strong>I want<strong> to change <strong>this<strong> text, 
but <strong>I can't<strong>. <strong>Why?<strong>.

I'm using the following regex:

\x26lt;(.*?)\x26gt;

(globally, and replacing it with "<$1>")

I guess the problem is I can't tell how many matches will be found, and how to refer to each one. Maybe in Perl I could have used $+, but that isn't working. I'm doing this with the regex module of Yahoo Pipes. It should be very similar to PHP implemenations, afaik.

How can I use each match separately in Yahoo Pipes?


Solution

  • It might be easier to replace the &lt; and the &gt; independently. That way it becomes a simply find-replace that doesn't need to use back-references.