正则提取字符串IP地址,返回IP列表

 

public class Main {


    public static void main(String args[]) {
        String str = "10.11.90.1 asedfa 1.1.1.1";
     List list = new ArrayList();
        Pattern pattern = Pattern.compile("[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}");
        Matcher matcher = pattern.matcher(str );
        while (matcher.find()) {
            String ip = matcher.group(0);
       list.add(ip);
        }
    }
}

 

posted @ 2019-04-09 15:41  高圈圈  阅读(742)  评论(0编辑  收藏  举报