I want to capture groups matching a pattern where the input can contain this group one or more times.
Example:
input = 12361 randomstuff371 12 Mar 16 138more random381 stuff73f
I want to capture the "12 Mar 16".
From this I have easily used the regex:
pattern = (".*(\\d{2}\\s\\w+\\s\\d{2}).*");
However my trouble is that when the input can contain more than one of these groups, I'm not able to capture the subsequent matches.
Example:
input = randomstuff371 12 Mar 16 14 Jan 15 13 Feb 16 138more random381 stuff73f
Such that:
group 1 = 12 Mar 16
group 2 = 14 Jan 15
group 3 = 13 Feb 16
The number of these groups to match will always vary, and so I'm wondering if there is a regex that will work over inputs that contain 1 or more of these groups. I have tried:
pattern = (".*(\\d{2}\\s\\w+\\s\\d{2}\\s)+.*"); \\ Not sure about whitespace at the end
However It doesn't work. Is this more to do with how I'm storing these captured groups? I cannot predetermine the number of groups that I will need, especially since the regex needs to work over many of these inputs.
I feel as though I'm just better off capturing the entire segment of dates and handling it later with matcher.find()
to count the number of groups that I require.
Any help will be much appreciated.