Page 1 of 1

replaceText across line breaks

Posted: Sat Jan 04, 2014 9:27 pm
by slindstrom
Regular expressions are new to me and perplexing. In the following snippet I am trying to completely remove everything from and including the "<" in the <ul> tag through the ">" in the </ul> tag.

<div class="title">
<ul class="iconkey" style="color: #000; font-weight: bold;">
<li>ICON KEY:</li>
<li class="location-2">City</li>
</ul>
</h2>
</div><!-- /Title -->

To that end, the following works fine if there are no line breaks between "<ul" and "</ul>." But it doesn't work when there are CRs in the text.

function removeIconKey tagVar
put "<ul class=" & quote & "iconkey" & quote & ".*</ul>" into iconUL
return replaceText(tagVar,iconUL, empty)
end removeIconKey

Can this regex be modified so that it will work even with CRs in the text? If so, how? I've tried a couple things in online regex testers that work but they fail in LiveCode.

Best,
Sieg

Re: replaceText across line breaks

Posted: Sun Jan 05, 2014 9:06 am
by Thierry
Hi Sieg,
Can this regex be modified so that it will work even with CRs in the text?
Yes. Prefix your regex with (?ms); then the dot will match a cr..
I've tried a couple things in online regex testers that work but they fail in LiveCode.
Unfortunately, not that simple :(


HTH,

THierry

Re: replaceText across line breaks

Posted: Mon Jan 06, 2014 10:24 pm
by slindstrom
Thanks, Thierry! That worked. :)