我需要帮助,我有一个类似的字符串
LOCALHOST = https://192.168.56.1
我想获取“LOCALHOST”和 IP 地址,然后将其保存到 HashMap
这是我到目前为止的代码,我不知道如何使用正则表达式,请帮助我想要的输出在 HashMap {LOCALHOST=192.168.56.1}
public static void main(String[] args) {
try {
String line = "LOCALHOST = https://192.168.56.1";
//this should be a hash map
ArrayList<String> urls = new ArrayList<String>();
//didnt know how to get two string
Matcher m = Pattern.compile("([^ =]+)").matcher(line);
while (m.find()) {
urls.add(m.group());
}
System.out.println(urls);
} catch (Exception e) {
System.out.println("Error: " + e.getMessage());
}
}
感谢您的帮助