Posso trasformare stringa #ff00fffirstword#445533secondword#008877thirdword
atrasformo '# ff00fffirstword # 445533secondword # 008877thirdword' in formato tag HTML
<font color='#ff00ff'>firstword</font><font color='#445533'>secondword</font><font color='#008877'>thirdword</font>
Utilizzando regexp in javascript o ActionScript3 programma?
Ho provato il codice qui sotto, ma non è perfetto (codice ActionScript3):
var pat:RegExp = /(#\w{6})([^#]+)/g;
var html:String = t.replace(pat, "<font color=\'$1\'>$2</font>");
trace(html); // output :<font color='#ff00ff'>firstword</font><font color='#445533'>secondword</font><font color='#008877'>thirdword</font>
Se c'è un altro #
in quella stringa, l'uscita sarebbe non essere come voglio che sia. Non so come scrivere una regexp più forte per raggiungere questo obiettivo.
Per inciso, 'tag font' è deprecato e non è garantito il funzionamento in futuro. È preferibile utilizzare CSS, ad es. ' ...' –