-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,291
  • 8
  • 62
  • 86
  • 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
  • 405,095
  • 59
  • 585
  • 614
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,695
  • 4
  • 28
  • 39