I am looking for a way to replace specific content using a regex with the same number of characters but replacing them with a character of my choice.
For instance:
content: "abcdefghi*!?\"asd";
should be transformed into:
content: "-----------------";
This is the regex I am using:
new RegExp("('|\").*('|\")", "gm")
Despite following advice from this answer on StackOverflow, my attempt is not successful:
source_text_safe = source_text.replace(new RegExp("('|\").*('|\")", "gm"), function ($0, $1, $2, $3) {
return $1 + (new Array($2.length + 1).join("-")) + $3;
});
When applied to 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
}
The output obtained is not as expected, indicating an issue with the current implementation.
Interestingly, when replacing the content with null using the same regex, it works perfectly fine, suggesting that the problem might lie elsewhere.
Any suggestions or guidance would be greatly appreciated!