Java regularizes multiple IPs to find out the matching results

package com.yunfatong.evidence.utils;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.poi.excel.ExcelBase;
import cn.hutool.poi.excel.ExcelUtil;
import cn.hutool.poi.excel.ExcelWriter;
import cn.hutool.poi.excel.StyleSet;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.Font;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFCellStyle;

import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Test {


    public static void main(String[] args) {
        String str = "10.255.130.32;0.0.0.0;192.168.100.10";

//1.创建匹配模式
        Pattern pattern = Pattern.compile("10\\.255\\.130\\.32|192\\.168\\.100\\.10");//匹配一个或多个数字字符
//2.选择匹配对象
        Matcher matcher = pattern.matcher(str);
//与谁匹配?与参数字符串str匹配
        int count = 0;
        while (matcher.find())//matcher.find()用于查找是否有这个字符,有的话返回true
        {
            System.out.println("第" + (++count) + "次找到");
            //start()返回上一个匹配项的起始索引
            //end()返回上一个匹配项的末尾索引。
            System.out.println(str.substring(matcher.start(),matcher.end()));
        }

    }
}

Guess you like

Origin blog.csdn.net/haoweng4800/article/details/131219834