PHP regex alphanumeric, delimited by non-alpha numeric

I would like to get all occurrences

@something

limited to any non-alpha numeric character or space.

I tried

[^ A-Za-z0-9 \ c] @ (\ S) [^ A-Za-z0-9]

but it retains the space after the word.

I would be glad for any help, thanks.

Edit: So the question will be clear, I want to get a match from

Line start @ word1 something @ word2, @ word3

all '@ word1', '@ word2', '@ word3'

+3


source to share


2 answers


Is this what you want?

@\w+

      

Demo

preg_match_all('#(@\w+)#', 'Line start @word1 something @word2,@word3', $matches);
print_r($matches[1]);

      



Taking from Madbreak's comment to exclude @

, preceded by any character, use instead

 (?<!\w)@\w+(?=\b)

      

Demo

+1


source


it

preg_match_all('/[^@]*@(\S*)/', 'blabla @something1 blabla @something2 blabla', $matches);
print_r($matches[1]);

      



prints

Array
(
    [0] => something1
    [1] => something2
)

      

0


source







All Articles