程序员的资源宝库

网站首页 > gitee 正文

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

sanyeah 2024-04-12 17:39:17 gitee 3 ℃ 0 评论

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()));
        }

    }
}

 

 

Tags:

本文暂时没有评论,来添加一个吧(●'◡'●)

欢迎 发表评论:

最近发表
标签列表