replaceText across line breaks

Bringing the internet highway into your project? Building FTP, HTTP, email, chat or other client solutions?

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
slindstrom
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 29
Joined: Mon Apr 09, 2012 8:53 pm

replaceText across line breaks

Post by slindstrom » Sat Jan 04, 2014 9:27 pm

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

Thierry
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 875
Joined: Wed Nov 22, 2006 3:42 pm

Re: replaceText across line breaks

Post by Thierry » Sun Jan 05, 2014 9:06 am

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
!
SUNNY-TDZ.COM doesn't belong to me since 2021.
To contact me, use the Private messages. Merci.
!

slindstrom
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 29
Joined: Mon Apr 09, 2012 8:53 pm

Re: replaceText across line breaks

Post by slindstrom » Mon Jan 06, 2014 10:24 pm

Thanks, Thierry! That worked. :)

Post Reply