Page 1 of 1
simple regex replacetext question
Posted: Wed Mar 06, 2019 12:27 am
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
Re: simple regex replacetext question
Posted: Wed Mar 06, 2019 11:59 am
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.
Re: simple regex replacetext question
Posted: Wed Mar 06, 2019 12:35 pm
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
Re: simple regex replacetext question
Posted: Wed Mar 06, 2019 12:55 pm
by bogs
Re: simple regex replacetext question
Posted: Wed Mar 06, 2019 6:22 pm
by slindstrom
Thanks, Thierry! Both work with my data.
Re: simple regex replacetext question
Posted: Wed Mar 06, 2019 6:45 pm
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!
Re: simple regex replacetext question
Posted: Wed Mar 06, 2019 6:50 pm
by Klaus
He's the Regex 'ero!

Re: simple regex replacetext question
Posted: Wed Mar 06, 2019 8:10 pm
by Thierry
slindstrom wrote:
Thanks, Thierry! Both work with my data.
I'm glad that it works for you.