I want to write date and other information from a string in java using a regex.
I group my template as follows
"( ( date_variation_1 | date_variation_2) (some_other_info) ) "
And now I want to extract the matched string like this,
group0 - the whole match
group1 - date
group2 - some other information
My problem is that I need to use parentheses inside date_variation_1, date_variation_2 and some_other_info, and these parentheses will also be treated as group separators.
Is there any easy work for this, i.e. define some other special charter as an external separator of the group, rather than parentheses?
date_variation_1:
"(((?:Monday|Tuesday|Wednesday|Thursday|Friday|Saturday|Sunday|Tues|Thur|Thurs|Sun|Mon|Tue|Wed|Thu|Fri|Sat))"
+ "(\\s+)"
+ "((?:[0]?[1-9]|[1][012])[-:\\/.](?:(?:[0-2]?\\d{1})|(?:[3][01]{1}))[-:\\/.](?:(?:\\d{1}\\d{1})))(?![\\d])"
+ "(\\s+)"
+ "((?:(?:[0-1][0-9])|(?:[2][0-3])|(?:[0-9])):(?:[0-5][0-9])(?::[0-5][0-9])?(?:\\s?(?:am|AM|pm|PM))?))";
source