1

If I gave you a string as such:

Image of text

If you look closely in the text there are commas in places like:

>, ., here, try 

The first two are common and need to be removed, the last one is normal and should stay in. Most people would suggest:

replace(/,/g, '') 

How ever the issue is that will remove all commas. Right now its safe to assume that any comma after a closing bracket or a period can be removed. How ever any other comma should stay in.

Any help on this would be appreciated I don't know if regex is appropriate or if there is a underscore way of doing this or what.

2
  • try a regex where if the comma is preceded by a character that's not a-zA-Z then remove Commented Dec 7, 2015 at 19:04
  • Perhaps, .replace(/\B,\B/g, '') can be used. Commented Dec 7, 2015 at 19:24

1 Answer 1

1

Instead of replacing all commas with an empty string, replace all >, with > and all ., with ..

replace(/>,/g, '>') then replace(/\.,/g, '.')

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

2 Comments

Issue with the second replace, it turns any comma into a . The first one works as desired.
Woops, . matches any character. You need to use \. to match only the . character. I've updated the answer.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.