[Solved] How to replace -a- with where a can be anything [closed]


You’re looking for a capture group, which you can then use as a substitution:

"-a-".replace(/-(.)-/g, "<$1>"); // <a>

There, the ( and ) define the capture group, the . inside means “any one character here” (adjust as necessary, perhaps .+), and in the replacement string, $1 means “the value of the first capture group.”

5

solved How to replace -a- with where a can be anything [closed]