I would like to know how to take parts of a long string to a string array. For example turing: String str = "hi im john and my email is <john@hotmail.com> and my number is <0123456789>"
to String[] strarray = {"john@hotmail.com", "0123456789"}
Something like this would work :
public static void main(String... args) throws Exception {
String str = "hi im john and my email is <john@hotmail.com> and my number is <0123456789>";
Pattern p = Pattern.compile("<(.*?)>");
Matcher m = p.matcher(str);
while(m.find()) {
System.out.println(m.group(1));
}
}
O/P :
john@hotmail.com
0123456789
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.