class="java">package excel; import java.util.Arrays; import java.util.regex.Pattern; public class ObtainNum { public static void main(String[] args) { String content = "满39元减2元"; //正则表达式,用于匹配非数字串,+号用于匹配出多个非数字串 String regEx="[^0-9]+"; Pattern pattern = Pattern.compile(regEx); //用定义好的正则表达式拆分字符串,,把字符串中的数字留出来 String[] cs = pattern.split(content); System.out.println(Arrays.toString(cs)); } }
?