RegEx ActionScript 3 [cerrado]

I am trying to figure out a regex to strip extra single quotes so that I would end up with only one single quote. To explain my question better, here is an example.

Let's say I have 3 different strings such as this ones.

(dos comillas simples)

Name<span fontSize=''16'' baselineShift=''superscript''>ABC</span>

(three single quotes)

Name<span fontSize='''16''' baselineShift='''superscript'''>ABC</span>

(four single quotes)

Name<span fontSize=''''16'''' baselineShift=''''superscript''''>ABC</span>

I am trying to sanitize the string to end up with this:

Name<span fontSize='16' baselineShift='superscript'>ABC</span>

I tried several online tools. This one is my favourite one: But I just can't get it right.

Could someone please help me out? Any tips and suggestions would be greatly appreciated.

Gracias de antemano!

preguntado el 10 de septiembre de 13 a las 01:09

2 Respuestas

Has probado '+?

var str:String = "Name<span fontSize=''''16'''' baselineShift=''''superscript''''>ABC</span>";
trace( str.replace(/'+/g, "'") );

Respondido el 10 de Septiembre de 13 a las 01:09

I am just slapping my forehead right now. :) Thank so much, Marty! - bustedsanta

Have you looked at the docs for AS3's RegEx code? AS3 Replace Podrías probar algo como esto

var myPattern:RegExp = /'{2,100}/g;  
var str:String = "fontSize=''''16''''";
trace(str.replace(myPattern, "'"));  

The '{2,100} essentially looks for a match of ' that occurs between 2 - 100 times and replaces it with a single '.

Respondido el 10 de Septiembre de 13 a las 01:09

What if there are 101? - Marty

Then you really need to reconsider how your program is generating the ' :) - ermagana

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.