0

I need to get the text after the '?' sign, nut my regex doesn't work and I have java.lang.IllegalStateException: No match found, so why is that and how to make it work?

import java.util.regex.Pattern;

class Test
{
    public static void main(String[] args)
    {
        String rawString = "junk_text?precious_text";
        String parsedString = Pattern.compile("\\?.+").matcher(rawString).group();
        System.out.println(parsedString); // need to print precious_text
    }
}
Denys_newbie
  • 1,140
  • 5
  • 15
  • 2
    You created a `Matcher`, but haven't attempted to actually "match" using it before trying to get the `group`s of the result. Please re-read the documentation. – Karl Knechtel Sep 21 '20 at 20:52
  • also you don't have any groups defined, so you can't extract any groups – Lino Sep 21 '20 at 21:24
  • @Lino that's not how that works. group() with no arg gets the entire match, and does not require any actual groups. – rzwitserloot Sep 21 '20 at 21:47

0 Answers0