Java 正则提取银行短信内容

使用 matcher.group()

Pattern pattern = Pattern.compile("[\\*0-9\\.:]+");
Matcher matcher = pattern.matcher("【华夏银行】您的华夏卡(**6999),05月29日11:03到账人民币0.34元,银联代付,余额12.86元");
while (matcher.find()) {
    String group = matcher.group();
    System.out.println(group);
}

使用 mathcer.replaceAll()

Pattern compile = Pattern.compile("[^\\d\\.:]+");
Matcher matcher = compile.matcher("【华夏银行】您的华夏卡(**6999),05月29日11:03到账人民币0.34元,银联代付,余额12.86元");
String s = matcher.replaceAll(" ");
System.out.println(s);

使用 string.split()

String content = "【华夏银行】您的华夏卡(**6999),05月29日11:03到账人民币0.34元,银联代付,余额12.86元";
String[] strings = content.split("[^\\d\\.:]+");
System.out.println(strings);

猜你喜欢

转载自www.cnblogs.com/Godfunc/p/10690221.html