In Perl/PHP regex is’s possible to match a sequence and get an array with matched sequences:
preg_match('/20[0-1][0-9]/', $inputstring, $array_return); // PHP
I can’t figure out how to do this in Java. match.group() returns the whole string.
Is this impossible?
If you only want to return part of the match, use capturing parentheses.
For example, to get only the year out of an MM/DD/YYYY date, the regex you want is
I don’t know the specifics of doing it in Java (you might need to escape some characters, for example), but just knowing that you should look for “capturing groups” should be of use.