Regex pattern to find full stop, exclamation mark or question mark in Java

I am new to regex. Here is a model I could think of:

Pattern pattern = Pattern.compile("[.!?]");

As the documentation says [abc] a, b, or c (simple class)

. But I was somehow wrong.: - (


source to share

1 answer

This works for me:

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Main {

    public static void main(String[] args) throws IOException {
        Pattern pattern = Pattern.compile("[.!?]");
        Matcher m = pattern.matcher("Hello?World!...");
        while (m.find()) {



So what is your problem more precisely?



All Articles