Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
のすべての発生を取得したい
@なにか
英数字以外の文字またはスペースで囲まれています。
私は試した
[^ A-Za-z0-9 \ s] @(\ S)[^ A-Za-z0-9]
しかし、それは単語の後にスペースを含め続けます。
助けてくれて嬉しいです、ありがとう。
編集:問題は明らかだろう、私はからマッチを得たい
行開始@word1何か@word2、@ word3
すべて'@word1'、'@ word2'、'@ word3'
これは、あなたの望むことですか?
@\w+
デモ
preg_match_all('#(@\w+)#', 'Line start @word1 something @word2,@word3', $matches); print_r($matches[1]);
Madbreakのコメントから取得@し、任意の文字が前に付いているものを除外するには、代わりにこれを使用します
@
(?<!\w)@\w+(?=\b)
これ
preg_match_all('/[^@]*@(\S*)/', 'blabla @something1 blabla @something2 blabla', $matches); print_r($matches[1]);
プリント
Array ( [0] => something1 [1] => something2 )