java中twitter风格的正则表达式匹配

java中twitter风格的正则表达式匹配,java,Java,我想提取字符串中“@”对应的单词并将其保存在列表中: 例如: "This is @crazy_boy crazy" should give ["crazy_boy"] "This is @crazy_boy crazy @foobar" should give ["crazy_boy","foobar"] "This statement is boring" should give [] //or whatever is an empty list String input = "T

我想提取字符串中“@”对应的单词并将其保存在列表中:

例如:

 "This is @crazy_boy crazy" should give ["crazy_boy"]

 "This is @crazy_boy crazy @foobar" should give ["crazy_boy","foobar"]

 "This statement is boring" should give [] //or whatever is an empty list
String input = "This is @crazy_boy crazy @foobar";
Matcher matcher = Pattern.compile("(?<=@)\\w+").matcher(input);
while (matcher.find())
  System.out.println(matcher.group());
用python

  targets = re.findall(r'(?<=@)\w+', text)
targets=re.findall(r'(?请参阅)。您需要迭代匹配,例如:

 "This is @crazy_boy crazy" should give ["crazy_boy"]

 "This is @crazy_boy crazy @foobar" should give ["crazy_boy","foobar"]

 "This statement is boring" should give [] //or whatever is an empty list
String input = "This is @crazy_boy crazy @foobar";
Matcher matcher = Pattern.compile("(?<=@)\\w+").matcher(input);
while (matcher.find())
  System.out.println(matcher.group());