0

I have a Address like

 Address : 273A-84, Sundharam Street,, Ganthi Path, Kovai,,,,India,641001

If string has more than 2 commas i want to replace with single comma.

In above address next to street and next to kovai there is multiple commas.I want to replace with single comma.

My expected output is:

Address : 273A-84, Sundharam Street,Ganthi Path,Kovai,India,641001

Please suggest regular expression.

2
  • replace(/,,*/g,',') Commented Nov 21, 2014 at 10:25
  • @Baskar I added answer for you question, could you give feedback, problem solved or not ? Commented Dec 4, 2014 at 20:13

2 Answers 2

2
var str = "Address : **273A-84, Sundharam Street,, Ganthi Path, Kovai,,,,India,641001**";

str.replace(/\,{1,}/gi, ',');

DEMO:http://jsbin.com/sejuma/2/

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

Comments

0

You can try this:-

 var str="Address : 273A-84, Sundharam Street,, Ganthi Path, Kovai,,,,India,641001 ";
    res = str.replace(/^[, ]+|[, ]+$|[, ]+/g, ",").trim();
    alert("{" + res+ "}");

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.