你可以使用正则表达式来提取字符串中的IP地址。下面是一个示例代码:

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

public class Main {
    public static void main(String[] args) {
        String str = "jdbc:dm://127.0.0.1:5236/PLS";
        String pattern = "\\b(?:\\d{1,3}\\.){3}\\d{1,3}\\b";

        Pattern regex = Pattern.compile(pattern);
        Matcher matcher = regex.matcher(str);

        if (matcher.find()) {
            String ipAddress = matcher.group();
            System.out.println("IP地址: " + ipAddress);
        } else {
            System.out.println("未找到IP地址");
        }
    }
}

输出结果为:

IP地址: 127.0.0.1
``
java获取字符串中的ip地址字符串为jdbcdm1270015236PLS

原文地址: https://www.cveoy.top/t/topic/iq7R 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录