-1

I want to replace xx with . in this string 100x100/<name>xx-somename-xxjpg but only xx comes next to jpg.

'100x100/<name>xx-somename-xxjpg'.replace(/(xx(jpg|jpeg|png))/,'$')
What I get -> 100x100/<name>xx-somename-$
What I expect-> 100x100/<name>xx-somename-.jpg

How do I do it?

3
  • 2
    look-ahead is your friend. Commented Jan 14, 2020 at 9:36
  • 1
    ^^ There has to be a good dupetarget for this. Commented Jan 14, 2020 at 9:37
  • 1
    See the linked question (there are lots, that may or may not be the best one), basically it's xx(?=jpg|jpeg|png). The (?=___) is the lookahead. Commented Jan 14, 2020 at 9:39

1 Answer 1

-2

'100x100/<name>xx-somename-xxjpg'.replace(/(xx)(?=jpg|jpeg|png)/,'.')

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

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.