java正则多个IP从中找出来匹配结果

复制代码
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()));
        }

    }
}
复制代码

 

 

posted @   _Phoenix  阅读(64)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 如何调用 DeepSeek 的自然语言处理 API 接口并集成到在线客服系统
· 【译】Visual Studio 中新的强大生产力特性
· 2025年我用 Compose 写了一个 Todo App
点击右上角即可分享
微信分享提示