gpt4 book ai didi

java - 正则表达式从 Jdbc url 中查找主机名

转载 作者:行者123 更新时间:2023-11-30 09:26:42 31 4
gpt4 key购买 nike

我是正则表达式的新手。我想使用正则表达式从 postgreSQL jdbc URL 中检索主机名。

假设 postgreSQL url 是 jdbc:postgresql://production:5432/dbname。我需要检索“生产”,这是主机名。我想尝试使用正则表达式而不是 Java 拆分函数。我试过

Pattern PortFinderPattern = Pattern.compile("[//](.*):*");
final Matcher match = PortFinderPattern.matcher(url);
if (match.find()) {
System.out.println(match.group(1));
}

但它匹配从主机名到结尾的所有字符串。

最佳答案

Pattern PortFinderPattern = Pattern.compile(".*:\/\/([^:]+).*");

关于java - 正则表达式从 Jdbc url 中查找主机名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14895284/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com