Pharo punctuation marks

112 views Asked by At

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.

1

There are 1 answers

0
Iain Fraser On BEST ANSWER

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.