Is there a way to get the text from a java.util.regex.Matcher? It seems to be write-only. There’s method to set it (reset(CharSequence input)), but no getter (unless I’m overlooking it). There’s also a method for getting the pattern (pattern()), but the text is private without any getter. Why?
Is there a way to find out if a match was attempted other then calling e.g. group() and catching the IllegalStateException?
I’m asking this because I’m using a Matcher as a member and don’t want to repeat the information in additional members, as it clobbers the class needlessly.
As the documentation shows, you’re right : there is no way to get the text from the matcher or to know if a matching operation has been executed.
You could encapsulate the matcher inside a custom rusable class holding the state for you :