How do I delete everything between two tags in a string?

Get help using Construct 2

Post » Wed Jul 26, 2017 12:06 pm

Hi,

I have an HTML string with lots of tags (something like this:)
Code: Select all
<A> text1 </A>
<B> text2 </B>
<C> text3
more text3  </C>
<D> text4  </D>

and I want to delete some of them. I think this could be done with RegexReplace but I don't know how. What should my RegexReplace expression be if I want to delete (for example) everything from <C> to </C>?
B
18
S
5
Posts: 129
Reputation: 1,486

Post » Thu Aug 03, 2017 12:07 am

Bump
B
18
S
5
Posts: 129
Reputation: 1,486

Post » Thu Aug 03, 2017 3:06 pm

I think I found a solution:
Code: Select all
RegexReplace( String , "<C>[\s\S]*?<\/C>" , "g" , "")

But I don't understand why this doesn't work in Construct 2, it works perfectly in http://www.regexpal.com/. Even RegexMatchCount returns 0, is it maybe a C2 bug?
B
18
S
5
Posts: 129
Reputation: 1,486

Post » Sat Aug 05, 2017 3:11 pm

Bump
B
18
S
5
Posts: 129
Reputation: 1,486

Post » Sat Aug 05, 2017 3:31 pm

Might want to look for a javascript solution.
That's not just plain ole text, its formatted html on different lines.
Image ImageImage
B
168
S
50
G
164
Posts: 8,228
Reputation: 105,575

Post » Sat Aug 05, 2017 4:03 pm

@newt
newt wrote:Might want to look for a javascript solution.

I tried with this:
Browser --> Execute Javascript:
Code: Select all
"var str = '"&varWithMyString&"';
str= str.replace(/<C>[\s\S]*?<\/C>/, '');
c2_callFunction('myFunction',[str]);"

Function --> On "myFunction" --> Set text to Function.Param(0)

This should work but... it doesn't :|
newt wrote:That's not just plain ole text, its formatted html on different lines.

It doesn't matter, it doesn't work with plain text either. I've already tried. Anyway, if it works at http://www.regexpal.com/, it should also work in C2...
B
18
S
5
Posts: 129
Reputation: 1,486

Post » Sat Aug 05, 2017 5:34 pm

ImageImageImage
B
71
S
21
G
221
Posts: 3,649
Reputation: 124,227


Return to How do I....?

Who is online

Users browsing this forum: blackhornet and 8 guests