JAVA 的用法
获取之间的字符串
public static void main(String[] args) {
String rex = "(?<=需支付:).*?(?=元)";
String str = "您好,您需支付:250元";
Pattern pattern = Pattern.compile(rex);
Matcher matcher = pattern.matcher(str);
if(matcher.find()) {
//打印 250
System.out.println(matcher.group());
}
String rex = "(?<=需支付:).*?(?=元|分)";
String str = "您好,您需支付:250分";
Pattern pattern = Pattern.compile(rex);
Matcher matcher = pattern.matcher(str);
if(matcher.find()) {
//打印 250
System.out.println(matcher.group());
}
}
匹配中文逗号 或者 英文逗号结尾
AAA默认值,BBBB
AAA默认值,BBBB
public static void main(String[] args) {
String s = "斯大法官撒地方默认值100,澳四国地方官方";
String s1 = ReUtil.get("(?<=默认值).*?(?=,|,)", s, 0);
System.out.println(s1);
}
// 匹配 00125 00 01
boolean contains = ReUtil.contains("^0\\d+", "00");
提取数字
String regEx="[^1-9]";
Pattern p = Pattern.compile(regEx);
p.matcher("sdfsd121asdfsd").replaceAll("").trim()
标签:rex,String,正则表达式,matcher,正则,自用,Pattern,pattern,250 From: https://blog.51cto.com/u_14976802/5932940