preg_match all words start with an @?

前端 未结 5 1807
栀梦
栀梦 2021-01-25 08:05

i\'m not very firm with regular Expressions, so i have to ask you:

How to find out with PHP if a string contains a word starting with @ ??

e.g. i have a string l

5条回答
  •  别那么骄傲
    2021-01-25 08:57

    Just incase this is helpful to someone in the future

    /((?

    This will match any word containing alphanumeric characters, starting with "@." It will not match words with "@" anywhere but the start of the word.

    Matching cases:

    @username
    foo @username bar
    foo @username1 bar @username2
    

    Failing cases:

    foo@username
    @username$
    @@username
    

提交回复
热议问题