I have two regular expressions, one pulling out usernames from a csv string, and the other pulling out emails.
the string format is like this:
String s = "name lastname (username) <[email protected]>; name lastname (username) <[email protected]>; name lastname (username) <[email protected]>";
the code for my regular expressions are like this.
Pattern pattern = Pattern.compile("(?<=\()[^\)]+");
Matcher matcher = pattern.matcher(s);
Pattern pattern2 = Pattern.compile("((?<=<)[^>]+)");
Matcher matcher2 = pattern2.matcher(s);
while (matcher.find() && matcher2.find()) {
System.out.println(matcher.group() + " " + matcher2.group());
}
I've found several qeustions about merging regexes, but from the answers i haven't been able to figure out how to merge mine.
my printouts show:
"username [email protected]"
would I be able to print out the same from a single matcher, using one regex?
obs: this is a school assignment, which means i do not "need" to merge them or do any more, but i'd like to know if it is possible, and how difficult it would be.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…