I have been using following Regex to parse @username from posts in my application.
'/(^|\s)#(\w*[a-zA-Z_]+\w*)/
Can somebody explain me the purpose of (^|\s). What if I omit that part?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
(^|\s)either matches the beginning of a string (^) or a space character (\s). This is in order to preventhallo#worldfrom matching as a mention.An alternative to that is using
\b(a word boundary). It has slightly different semantics, but it should work in this case.