Get Two Specific Word Using Regex and Save it to HashMap
I need a help, I have a String like
LOCALHOST = https://192.168.56.1
I want to get the "LOCALHOST" and the IP address then save it to HashMap
This is my code so far, I didnt know how to use regex, please help The
output that I want is in HashMap {LOCALHOST=192.168.56.1}
public static void main(String[] args) {
try {
String line = "LOCALHOST = https://192.168.56.1";
//this must 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());
}
}
Thank you for the help
No comments:
Post a Comment