No match found in simple regex

Given a token in the format “word_suffix”, I want to match and capture the “suffix” part.

For instance, in “Peter_NNP” I want to capture “NNP”. I wrote:

        String p="Peter_NNP";
        Matcher matcher=Pattern.compile(".+_(.*s)").matcher(p);

instead of printing “NNP” as I would expect, it arises the following exception:

Exception in thread "main" java.lang.IllegalStateException: No match found
at Source)

Note that “word” and “suffix” part can be made of any character.

Source: regex

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.