You need to invoke m.find()
or m.matches()
first to be able to use m.group
.
find
can be used to find each substring that matches your pattern (used mainly in situations where there is more than one match)matches
will check if entire string matches your pattern so you wont even need to add^
and$
in your pattern.
We can also use m.lookingAt()
but for now lets skip its description (you can read it in documentation).