java正则匹配出浮点数的小demo

import java.util.regex.Pattern;
import java.util.regex.Matcher;
import java.util.*;
public class testzheng {
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        String content = "2020/08/18 16:07:43 [env] SetConfDirName= conf\n" +
                "2020/08/18 16:07:43 [env] auto detect rootPath= find_version\n" +
                "2020/08/18 16:07:43 [env] SetRootPath=/find_version\n" +
                "1180.0";
        String regex = "([1-9]\\d*\\.\\d*)";
        //分别是1.9这样的小数,0.9这样的小数和整数99
        //最后\\d不写匹配553时会匹配出553.$
        Pattern pattern = Pattern.compile(regex);
        Matcher matcher = pattern.matcher(content);
        while (matcher.find()) {
            System.out.println(matcher.group());
        }
    }
}

 

 

运行结果:

java正则匹配出浮点数的小demo_第1张图片

 

你可能感兴趣的:(BDWORK,intellij,idea,Java面向对象程序设计)