php正则表达式查找以#开头的字符串中的单词,并且不再重复#
我正在寻找一个正则表达式来查找以#开头的字符串中的单词,并且不再重复# 鉴于:php正则表达式查找以#开头的字符串中的单词,并且不再重复#,php,regex,preg-replace,arabic,hashtag,Php,Regex,Preg Replace,Arabic,Hashtag,我正在寻找一个正则表达式来查找以#开头的字符串中的单词,并且不再重复# 鉴于: Hi I'm #hany #هانى my Friend #john#john is ##here . good bye#all . 我希望最终结果如下: Hi I'm <a>#hany</a> <a>#هانى</a> my Friend #john#john is ##here . good bye#all . 你好,我是哈尼,我的朋友,约翰,约翰在这里。大家再
Hi I'm #hany #هانى my Friend #john#john is ##here . good bye#all .
我希望最终结果如下:
Hi I'm <a>#hany</a> <a>#هانى</a> my Friend #john#john is ##here . good bye#all .
你好,我是哈尼,我的朋友,约翰,约翰在这里。大家再见。
我用这个:
echo preg_replace('/(?!\b)#(\\S+)/','<a>$0</a>',$string);
echo preg_替换(“/(?!\b)#(\\S+/”、“$0”和$string);
我只想要以#
开头的单词,不要再像推特哈希标签那样使用哈希值。尝试以下模式:
echo preg_replace('/(?<=\s)(#[^#\s]+)(?=\s)/', '<a>$0</a>' ,$string);
echo preg\u replace('/(?尝试以下方法:
echo preg_replace('~(?<=\s|^)#[^\s#]++~um', '<a>$0</a>', $string);
echo preg#u replace(“~?它工作正常,但我想回显$1输出,如:嗨,我是哈尼,我的朋友,约翰,约翰在这里。再见,全部。另一个用于替换非英语单词输出,如:嗨,我是哈尼,我的朋友,约翰,约翰在这里。再见,全部。我在这里替换()?
echo preg_replace('~(?<=\s|^)#[^\s#]++~um', '<a>$0</a>', $string);
~ # pattern delimiter (instead of /, but it's the same)
(?<= # open a lookbehind (means "preceded by")
\s | ^ # a white character (space, tab, newline...) or the begining of the line
) # close the lookbehind
# # literal #
[^\s#]++ # all that is not a # or a white character, one or more times (possessive)
~ # delimiter
um # u for unicode string, m for multiline mode