赞
踩
package src.regularExpression; import java.util.regex.Matcher; import java.util.regex.Pattern; public class TimeUtil { public static void main(String[] args) { String[] temp; String str = "\n" + "2020-10-22T07:56:07.867Z,,,,asdasdasn" + "2020-10-22T07:56:22.874Z,,,,a's'da's" + "2020-10-22T07:59:33.348Z,,b"; String regex = "[0-9]{4}[-][0-9]{1,2}[-][0-9]{1,2}"; // String regex = "[0-9]{4}[-][0-9]{1,2}[-][0-9]{1,2}[T][0-9]{1,2}[:][0-9]{1,2}[:][0-9]{1,2}[.][0-999]{1}"; Pattern p = Pattern.compile(regex); Matcher matcher = p.matcher(str); if (matcher.find()) { System.out.println(matcher.groupCount()); System.out.println(matcher.group(0)); } temp = str.split(matcher.group(0)); for (String i:temp ) { System.out.println(i); } } }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。