Javascript regex para reemplazar / *

I would like to replace a string. I have tried this, which I thought would work, but it doesn't

string = "/*"
string.replace(/\/(?=\*)/g,"replaced")

I tried escaping the asterisk and leaving it alone but both didn't work.
Could somebody tell me the regex to replace /* y */ ?

preguntado el 27 de agosto de 11 a las 17:08

please format your code properly next time -

2 Respuestas

Lo siguiente debería funcionar:

/\/\*|\*\//g

Respondido 27 ago 11, 21:08

Thanks, this didn't work straight away but i pasted it above everything else and then it did. - Steve

Replace /* or replace */

var string = "/**"
string.replace(/(\/\*)|(\*\/)/g,"replaced")

Respondido 27 ago 11, 21:08

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