Tuesday, 15 April 2014

regex - How can i get content between dates using java regular expressions -



regex - How can i get content between dates using java regular expressions -

below code did not me content between dates.can please help me.

string res="05/22/2014 03:22:39.288 ffff gggg kkkkkk lllllll ssss 05/22/2014 03:22:39.288 oooooo ppppp qqqq rrrrrr sss 05/22/2014 03:22:39.378 mmmmmm nnn oooo "; string regex="((0?[1-9]|1[012])/(0?[1-9]|[12][0-9]|3[01])/((19|20)\\d\\d).*([01]?[0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9].[\\d]*)(.*?)((0?[1-9]|1[012])/(0?[1-9]|[12][0-9]|3[01])/((19|20)\\d\\d).*([01]?[0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9].[\\d]*)?"; matcher matcher = pattern.compile(regex).matcher(res); while(matcher.find()) { string grouping = matcher.group(); system.out.println(group); }

even tried below using string split regular look in java gives 1 result:

string regex="((0?[1-9]|1[012])/(0?[1-9]|[12][0-9]|3[01])/((19|20)\\d\\d).*([01]?[0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9].([\\d][^\\s]+)?)"; string[] split = res.split(regex);

you can utilize regex capture text:

(?<=\d{2}/\d{2}/\d{4} \d{2}:\d{2}:\d{2}\.\d{3} )(.*?)(?=(?: \d{2}/\d{2}/\d{4} \d{2}:\d{2}:\d{2}\.\d{3}|$))

and grab text in grouping #1 i.e.

matcher.group(1); working demo

java regex

No comments:

Post a Comment