【发布时间】:2015-04-23 19:53:36
【问题描述】:
我想删除以space 和# 符号开头的文本末尾的所有单词。
不应删除句子中的 URL 或主题标签。
示例文本:
hello world #dontremoveme foobar http://example.com/#dontremoveme #remove #removeme #removeüäüö
我试过了,但它删除了所有标签:
$tweet = "hello world #dontremoveme foobar http://example.com/#dontremoveme #remove #removeme #removeüäüö";
preg_match_all("/(#\w+)/", $tweet, $matches);
var_dump( $matches );
我的想法是检查从文本末尾开始的每个单词是否有前导 # 和前面的 space,直到不再是这种情况。
如何将其翻译成正则表达式?
【问题讨论】: