I need to replace the content found used a regex with the same number of characters using a character defined by me.
For example:
content: "abcdefghi*!?\"asd";
should becomes:
content: "-----------------";
This is my regexp:
new RegExp("('|\").*('|\")", "gm")
And this is my attempt took from this answer (Javascript Regex- replace sequence of characters with same number of another character):
source_text_safe = source_text.replace(new RegExp("('|\").*('|\")", "gm"), function ($0, $1, $2, $3) {
return $1 + (new Array($2.length + 1).join("-")) + $3;
});
But it doesn't work.
Using it on this input:
::selected {
color: purple
}
a {
color: purple
}
a:hover {
color: purple
}
a {
color: purple
}
a:not("foobar\";{}omg") {
content: 'example\';{} text';
content: "example\";}{ text"
}
a {
color: purple
}
I get this output:
::selected {
color: purple
}
a {
color: purple
}
a:hover {
color: purple
}
a {
color: purple
}
a:not("-117) {
content: '-150;
content: "-184
}
a {
color: purple
}
If I use the regexp replacing the content with null
it works fine, so is not a problem of regex.
Any help?