Domanda

Ho un testo fornito dall'utente e devo anteporre tutte le barre rovesciate e le virgolette singole con una barra rovesciata. Come farlo?

È stato utile?

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
scroll top