simple regex replacetext question

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

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

simple regex replacetext question

Post by slindstrom »

At least I think it's simple, though I've not figured out the syntax. How should I modify the following so that it works even if the contents of the table tag has a line break and sequence of spaces at the start of the second line? I've tried searching this forum but inevitably find discussions that are more complicated. Regex mostly confounds me, I find myself easily led astray. Thanks in advance!

put replaceText(tVar,"<table.*?>","<table>") into tVar
bogs
Posts: 5480
Joined: Sat Feb 25, 2017 10:45 pm

Re: simple regex replacetext question

Post by bogs »

While I replace very little text, I think when it comes to replacing html elements, you have to break them up (something to do with Lc parsing html).

For instance, i wrote a little utility to create a blockquote a long time ago. It wouldn't work till I broke the code to create the blockquote itself up -

Code: Select all

 put "<blockquote style=" & quote & "background-color: silver;" & quote & ">" & return & "<br>" before field 1
I also seem to remember this question coming up before a while back. If I come across that thread again, I'll post a link here.

*Edit - it might have been this thread, towards the bottom there are a couple of solutions for html and regex.
Image
Thierry
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 875
Joined: Wed Nov 22, 2006 3:42 pm

Re: simple regex replacetext question

Post by Thierry »

slindstrom wrote: put replaceText(tVar,"<table.*?>","<table>") into tVar
Hi,

Please try this one:

Code: Select all

replaceText( tVar,"(?ms)<table[^>]*?>","<table>")
or:

Code: Select all

replaceText( tVar,"(?ms)(?<=<table)[^>]*?(?=>)","")
Disclaimer: not tested, and as it is true ALL the time, writing a valid regex depends on the data.
So take this with a grain of salt, and test it with *your* datas.

Regards,

Thierry
!
SUNNY-TDZ.COM doesn't belong to me since 2021.
To contact me, use the Private messages. Merci.
!
bogs
Posts: 5480
Joined: Sat Feb 25, 2017 10:45 pm

Re: simple regex replacetext question

Post by bogs »

OOOoooo, that is slick Thierry. BTW, I love that function you wrote from the linked thread, it has come in handy many times since I found it, I give it 4 thumbs up ImageImageImageImage (needed my last thumb to hit enter) :D
Image
slindstrom
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 29
Joined: Mon Apr 09, 2012 8:53 pm

Re: simple regex replacetext question

Post by slindstrom »

Thanks, Thierry! Both work with my data.
SparkOut
Posts: 2984
Joined: Sun Sep 23, 2007 4:58 pm

Re: simple regex replacetext question

Post by SparkOut »

slindstrom wrote: Wed Mar 06, 2019 6:22 pm Thanks, Thierry! Both work with my data.
That's what I'd expect from Thierry, he's the regex hero.


---


Hi Thierry!
Klaus
Posts: 14324
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: simple regex replacetext question

Post by Klaus »

He's the Regex 'ero! :D
Thierry
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 875
Joined: Wed Nov 22, 2006 3:42 pm

Re: simple regex replacetext question

Post by Thierry »

slindstrom wrote: Thanks, Thierry! Both work with my data.
I'm glad that it works for you.
!
SUNNY-TDZ.COM doesn't belong to me since 2021.
To contact me, use the Private messages. Merci.
!
Post Reply