· 9 years ago · Oct 19, 2016, 11:04 AM
1Set<String> users = new HashSet<>(); // to avoid repeated mentions
2 for (Tweet t: tweets){
3 String line = t.getText();
4 String pattern = "(?<=^|(?<=[^a-zA-Z0-9-_\.]))@[A-Za-z0-9_-]+";
5 Pattern p = Pattern.compile(pattern);
6 Matcher m = p.matcher(line);
7 if (m.find()){
8 users.add(m.group().toLowerCase());
9 }
10
11@tony
12$$@yahoo$$
13john @john john
14@joules-
15@john-cassidy
16%%@jake%%
17@@@jake@@@
18dude$@jake$$
19$$$@jack$$$
20@@@jake@@@
21@john4
22@jake2$
23@johN3
24@rock-smith
25@John
26@gmail.com //should not return but does: wrong
27richard@mit.edu //should not find and it doesn't: good