How do I match words that begin with @ and ends with ;, ., :, or ?
The words can have any alphanumeric characters and may consist of underscores.
I have come up with ^@([a-zA-Z0-9_])*[:;, ]$ which seems to work for single word sentences alone.
^matches the start of a string (or line, in multi-line mode), while$matches the end, so you need to get rid of them:It is only capturing the last letter because the qualifier (the
*) is outside the brackets matching the capture. Move it inside and you get:If you want to capture the @ and trailing character too, just move them inside the brackets as well:
And as mentioned in the comments on the question, you may or may not want to restrict it to a certain number of characters:
(Of course, the length restriction could be added to any of the previous expressions, not just this last one).