title: Java Regular Expression for extracting mentioned name in Tweeter message
body: <p>I am writing a small program that extract username mentioned in a Tweeter's message by using regular expression. However, part of the program is failing in some test cases. Basically, the regex pattern specified below is able to match text1 but not text2. Now, the regex pattern below is only meant to match a specific test case when the first character in the string is "@" followed by a valid username in tweeter. I think I must have misunderstood this regex and used it wrongly. Will someone be able to shed some light on this please? </p>
  
  <pre><code>String validTweetPattern1 = "^[@]((?=.*[A-Za-z0-9])[\\w-_]+)";
  String text1 = "@mention";
  String text2 = "@mention @hello";
  
  System.out.println(Pattern.matches(validTweetPattern1, text1));  
  System.out.println(Pattern.matches(validTweetPattern1, text2));  
  
  Console Output:
  True
  False
  </code></pre>
  
  <p>Thanks in advance.</p>