0

I am trying to replace the same string *a*a consistently with *a.

Tried many variations of something like this, but none really worked:

s = s.replace( /\b*a*a\b/g, "*a");

So far running this leads to all xzy*a being replaced with xyz

0

2 Answers 2

0

* is a special regex character. If you want to match only an actual asterisk, then you have to escape it like this:

s = s.replace( /\*a\*a/g, "*a");

Working demo: http://jsfiddle.net/jfriend00/gvgshwyz/

Sign up to request clarification or add additional context in comments.

Comments

0

An asterisk is a special regex character.

You just have to escape it like this: \*a in place of *a

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.