我是新來的正則表達式。我想使用正則表達式從postgreSQL jdbc URL檢索主機名。 假設postgreSQL的網址將是jdbc:postgresql://production:5432/dbname
。我需要檢索「生產」,這是主機名。我想嘗試使用正則表達式,而不是使用Java分割函數。我試過正則表達式從Jdbc查找主機名url
Pattern PortFinderPattern = Pattern.compile("[//](.*):*");
final Matcher match = PortFinderPattern.matcher(url);
if (match.find()) {
System.out.println(match.group(1));
}
但是它匹配所有從主機名到最後的字符串。請幫助我。