-1

Is there any way to capture all the places in a String, where there are punctuation marks like '.,:;!?'

Basically, am looking for a regex that captures all the above.

Rekha
  • 105
  • 2
  • 4

1 Answers1

-1

What you're looking for is called a character class. A character class is a group of characters that you're saying can be matched at that position in the string. To make a character class you enclose your list of matchable characters in square brackets, like this:

[.,:;!?]

This will match only those punctuation characters.

Interestingly, you can also make a character class that will match anything except the list of characters you've specified. To do this, you start your character class with a ^.

[^.,:;!?]

Now this one will match anything except punctuation.

Iain Fraser
  • 6,089
  • 6
  • 38
  • 67