如题:提取字符串:export_20170717_out.log
对应的日期:20170717
package dodo; import java.util.regex.Matcher; import java.util.regex.Pattern; public class demo { static String cmd="export_20170717_out.log"; public static void main(String[] args) { String regex="\d{8}"; Pattern pa=Pattern.compile(regex); Matcher ma=pa.matcher(cmd); if(ma.find()){ System.out.println("取到的日期为:"+ma.group(0)); } } }
输出结果为:
取到的日期为:20170717