首页 > 解决方案 > 正则表达式日语单词无法逃脱

问题描述

标签: phpregexcharacter-encodingpreg-replacecjk

解决方案


I would use the following regex for a hashtag:

#\S+

This will match a leading # character, followed by one or more non whitespace characters (which would include Japanese Kanji).

Sample script:

$text = "#食への好きな人と繋かりたい #食への好きな人と繋がりたい #食べるの好きな人と繋がりたい";
echo $text . "\n";
$text = preg_replace("/#\S+/", "", $text);
echo $text;

The second echo prints just two spaces (which were separating the three hashtags in the original input);


推荐阅读