0

I tried:

var test = code.replace("-", "%2D");

but if code = "1-2-3", it only replaces one dash. How do I replace both?

1
  • use a regex match.. /-/ Commented Apr 15, 2013 at 14:02

1 Answer 1

4

Use //

var test = code.replace(/-/g, "%2D");
Sign up to request clarification or add additional context in comments.

2 Comments

Can you explain what /.../ is? What does the g do?
If i remember correctly g means global and /.../ is to initiate a regex expression

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.