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.
我正在尝试创建一个 PHP 正则表达式,如果任何单词以 '#' 开头,例如 '#ball',它将匹配。我试过这个
preg_match_all('/( #\w+)/u', $text, $matches);
但它会返回所有包含 '#' 的单词,例如 'pin#ball'。
尝试这个:
$sData = '#pin all#foo #bar'; preg_match_all('/(^|\s+)#([a-zA-Z]+)/', $sData , $rgMatches); //var_dump($rgMatches[2]);
试试这个正则表达式。
preg_match_all('/(?!\b\s*)#.*\b/', $text, $matches);