正则表达式如何匹配
我想提取一窜数字之后的那个字符
比如
String strMoney ="48000万";
String regex ="[0-9_._,]+(.*?)";
Pattern p = Pattern.compile(regex);
Matcher m = p.matcher(strMoney);
if(m.find()){
moneyText = m.group(0);
moneyLevel = m.group(1);
}
public static void main(String[] args) {
String strMoney ="48054354545400万";
String regex ="[0-9_._,]+(.*?)+[\u4e00-\u9fa5]";
Pattern p = Pattern.compile(regex);
Matcher m = p.matcher(strMoney);
String moneyText="";
String moneyLevel="";
if(m.find()){
moneyText = m.group(0);
moneyLevel = m.group(1);
}
System.out.println(moneyLevel+"========="+moneyText);
}
String strMoney = "48000万";
String regex = "([0-9_._,]+
[解决办法]
[a-zA-Z]+)";
String[] str = strMoney.split(regex);
System.out.println(str[1]);
public static void main(String[] args) throws Exception {
String strMoney = "48000万";
String regex = "\\D+";
Pattern p = Pattern.compile(regex);
Matcher m = p.matcher(strMoney);
if (m.find()) {
System.out.println(m.group(0));
}
}public static void main(String[] args) throws Exception {
String strMoney = "48000万数字";
Pattern p = Pattern.compile("[\u4e00-\u9fa5]");
Matcher matcher = p.matcher(strMoney);
if (matcher.find()) {
System.out.println(matcher.group());
}
}
public static void main(String[] args) throws Exception {
String strMoney = "啊数aa字48000万sxx数字";
Pattern pattern = Pattern.compile("(\\D*)(\\d*)([\u4e00-\u9fa5]).*");
Matcher matcher = pattern.matcher(strMoney);
if (matcher.find()) {
System.out.println(matcher.group(3));
}
}