-2

I'm trying to write a regex expression to match multiple characters such as , OR . OR : OR ( OR )

I have this

removePunctuation = /\.$|\,$|\:|\(|\)/;
word = rawList[j].replace(removePunctuation,"")

I just want to remove periods & commas at the end of the sentence but all instances of ( ) :

What am I doing wrong?

Morgan Allen
  • 3,065
  • 5
  • 50
  • 81
  • 1
    You want to look into [character sets](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp#character-sets) – epascarello Aug 29 '16 at 14:19

2 Answers2

3

You need to add the "g" qualifier if you want to remove all the punctuation.

removePunctuation = /\.$|\,$|\:|\(|\)/g;
Pointy
  • 389,373
  • 58
  • 564
  • 602
3

I'd go with something like this:

/[.,]+$|[:()]+/g

It'll match periods and commas at the end of a sentence, and brackets and colons everywhere.

Sebastian Lenartowicz
  • 4,549
  • 4
  • 28
  • 38