php删除字符串:fa fa phone famouse


php remove string: fa fa-phone famouse

我想删除字符串"fa famouse fa phone"的字符串fafa phone

我试过了:

preg_replace('/fa.+$/','', 'fa famouse fa-phone');

但现在它删除了fa的所有字符串。

preg_replace('/fa[ '-](phone)?/','','fa famouse fa-phone');

Regex:https://regex101.com/r/bJ3nE7/1


fa(文字)
[ '-]匹配空格或连字符
(phone)?与文字"phone"匹配0或1倍

所以我想删除字符串fa和所有以fa开头的字符串a-
但不是像famouse这样包含fa的其他字符串。

这是一种完成工作的方法:

echo preg_replace('/fa(?:-[-'w]+|'b)/', '', 'fa famouse fa-phone-small fabrics fantastic'),"'n";

输出:

famouse  fabrics  fantastic