escaping chars for the replaceText function

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
danielrr
Posts: 140
Joined: Mon Mar 04, 2013 4:03 pm

escaping chars for the replaceText function

Post by danielrr » Mon Apr 30, 2018 5:27 pm

I want to strip all the characters "()/\=" from any string passed to the replaceText function, but if I pass the list of the offending characters escaping the regex reserved chars using "\", the string remains unchanged:

Code: Select all

put replaceText("KAI\", "\\\/\(\)=", "")
KAI\
What I'm doing wrong?

LiveCode_Panos
Livecode Staff Member
Livecode Staff Member
Posts: 818
Joined: Fri Feb 06, 2015 4:03 pm

Re: escaping chars for the replaceText function

Post by LiveCode_Panos » Mon Apr 30, 2018 5:45 pm

Hi danielrr,

Try adding

Code: Select all

[]
around the characters you want to match. Omitting the [] means that it will try to match the exact sequence of

Code: Select all

\/()=
, rather than any of these characters.

This works for me:

Code: Select all

put replaceText("KAI\", "[\\\/\(\)=]", "")
Regards,
Panos
--

danielrr
Posts: 140
Joined: Mon Mar 04, 2013 4:03 pm

Re: escaping chars for the replaceText function

Post by danielrr » Mon Apr 30, 2018 7:53 pm

:D :D Thanks Panos

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”