I want to remove the strings fa and fa-phone of the string: "fa famouse fa-phone".
I tried:
preg_replace('/fa.+$/','', 'fa famouse fa-phone');
But now it removes all strings with fa
.
preg_replace('/fa[ \-](phone)?/','','fa famouse fa-phone');
Regex: https://regex101.com/r/bJ3nE7/1
fa
(literal)[ \-]
match a space or a hyphen(phone)?
match the literal 'phone' 0 or 1 times
So i want to remove the string fa and all the strings a beginning with fa-
But not other strings that contain fa like famouse for example.
Here is a way to do the job:
echo preg_replace('/fa(?:-[-\w]+|\b)/', '', 'fa famouse fa-phone-small fabrics fantastic'),"
";
Output:
famouse fabrics fantastic