I need a regex to replace strings like this:
aa:bb:c: //to be aabbc:
or
aa-bb-c- //to be aabbc-
I can do this by this code
text.replace(/.{2}[:-]/g, (match) => match.substring(0,2));
I am asking if this could be done by regex only without using replacer function like
text.replace(regex, "");
>Solution :
You can replace with regex capture group using (), which $1 means the first match group
text.replace(/(.{2})[:-]/g, "$1")