Simple code:
$matches = null; $returnValue = preg_match_all( '/#([^\s]+)/i', 'text#tag ' . PHP_EOL . '#tag5 #tagščřý continue', $matches ); var_dump($matches[1]);
displays
array 0 => string 'tag' (length=3) 1 => string 'tag5' (length=4) 2 => string 'tagščřý' (length=11)
Regular matching of everything after the hash (including numbers and Unicode characters). It is case insensitive /i .
If you need space before - just add \s to the regular expression '/\s#([^\s]+)/i' , the output will be:
array 0 => string 'tag5' (length=4) 1 => string 'tagščřý' (length=11)
source share