I need a javascript regular expression to match twitter usernames.
The username is entered by the user while signing up, so I don\'t want to distract them with too m
Another one that does the work is:
/(?
The first part (? matches @ if there is no character value before it.
That can be used as a filter for potential email addresses that have the format text@mail.com. Since there is text before @ the email address is not matched.
The second part [\w+]{1,15}\b matches a string of word characters namely a-z,A-Z,0-9,_ that are accepted in a twitter username. The word boundary anchor\b matches the space between a word character and a non word character. Non word characters are not accepted in the twitter username and are therefore excluded from the match because of \b.
Last but not least I provide a picture where I tested the proposed regex on the text provided in the second most voted answer by rayfranco to check for matches.
screenshot,
