How to avoid single quotes in Flash?

I have text provided by the user and I need to add all backslashes and single quotes with backslashes. How to do it?

+3
source share
2 answers
var string:String = "something 'is' \\fishy here";
trace(string);//something 'is' \fishy here
string = string.replace(/(['\\])/g, "\\$1");
trace(string);//something \'is\' \\fishy here
+5
source

Amarghosh's answer is this place. If you need an easy way to test the AS3 regex, Grant Skinner Regexr is awesome.

+2
source

Source: https://habr.com/ru/post/1724223/


All Articles