Come sfuggire alle virgolette singole in Flash?
-
08-07-2019 - |
Domanda
Ho un testo fornito dall'utente e devo anteporre tutte le barre rovesciate e le virgolette singole con una barra rovesciata. Come farlo?
Soluzione
var string:String = "something 'is' \\fishy here";
trace(string);//something 'is' \fishy here
string = string.replace(/(['\\])/g, "\\$1");
trace(string);//something \'is\' \\fishy here
Altri suggerimenti
La risposta di Amarghosh è perfetta. Se vuoi un modo semplice per testare regex AS3, Grant Skinner's Regexr è fantastico.
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow