Page 1 of 1

escaping chars for the replaceText function

Posted: Mon Apr 30, 2018 5:27 pm
by danielrr
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?

Re: escaping chars for the replaceText function

Posted: Mon Apr 30, 2018 5:45 pm
by LiveCode_Panos
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
--

Re: escaping chars for the replaceText function

Posted: Mon Apr 30, 2018 7:53 pm
by danielrr
:D :D Thanks Panos