0

I have a problem with replacing some strings with duplicated values. Here is snippet:

const firstStep = this.router.url.replace(/[\d\/]/g, '.');

Above returns when url like /project/1/cost-estimate it gives me .project...cost-estimate. So i need to replace this ... to . or project.project -> project.. How i do that ? Any advice ?

1
  • 1
    this.router.url.replace(/[\d\/]+/g, '.') Commented Aug 7, 2019 at 3:07

1 Answer 1

1

You can add a + to your regex to make the characters inside the bracket match one or more, effectively "squeezing" the result to one . character:

console.log("/project/1/cost-estimate".replace(/[\d\/]+/g, '.'));

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.