您可以在多个Regex之间使用Pipe(|)来匹配所有这些:
String s = "name lastname (username) ; name lastname
(username) ; name lastname
(username) ;";
// Matches (?<=\\()[^\\)]+ or ((?<=]+)
Pattern pattern = Pattern.compile("(?<=\\()[^\\)]+|((?<=]+)");
Matcher matcher = pattern.matcher(s);
while (matcher.find()) {
System.out.println(matcher.group());
}
输出:
username
mail@mail.something.dk
username
mail@mail.something.dk
username
mail@mail.something.dk
更新:
如果您只想在两者都存在时打印用户名和电子邮件,那么您需要拆分字符串;然后在每个上面应用以下正则表达式.
这是代码:
String s = "name lastname (username) ;
name lastname (username) ;
name lastname (username) ;";
String [] strArr = s.split(";");
for (String str: strArr) {
Pattern pattern = Pattern.compile("\\(([^\\)]+)(?:\\))\\s(?:\\]+)");
Matcher matcher = pattern.matcher(str);
while (matcher.find()) {
System.out.print(matcher.group(1) + " " + matcher.group(2));
System.out.println();
}
输出:
username mail@mail.something.dk
username mail@mail.something.dk // Only the last two have both username and email
redis list 取值 redis取list数据命令
List常用命令list 类似一个双端队列,即可以从左边 push 和 pop,也可以从右边 push 和 pop,底层其实是一个双端链表。可以实现分布式消息队列lpush list01 1 2 3 4 5
rpush list01 a b &nb
4.【Azure App Service for Windows】 PHP应用出现500 : The page cannot be displayed because an inte
5.【转载】 让老外不知所云的“中式英语”