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.
「#ball」のように「#」で始まる単語がある場合に一致する PHP REGEX を作成しようとしています。私はこれで試しました
preg_match_all('/( #\w+)/u', $text, $matches);
ただし、「pin#ball」のように「#」を含むすべての単語が返されます。
この正規表現を試してください。
preg_match_all('/(?!\b\s*)#.*\b/', $text, $matches);
これを試して:
$sData = '#pin all#foo #bar'; preg_match_all('/(^|\s+)#([a-zA-Z]+)/', $sData , $rgMatches); //var_dump($rgMatches[2]);