【发布时间】:2013-01-31 11:05:56
【问题描述】:
我是正则表达式的新手。我想使用正则表达式从 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));
}
但它匹配从主机名到结尾的所有字符串。
【问题讨论】: