I am trying to remove from a string all characters that do not match to a list of words.
my list of words could be:
- person
- animal
a string can look like this:
- 123-ea-person.jpg
- 456456-on-Person.jpg
- a-animal-dog.png
my result should look like this:
- person
- person
- animal
my approach:
preg_replace('/(person|animal)/i', '', '123-ea-person.jpg')
output:
123-ea-.jpg
expected output:
person
How can I reverse the pattern to get the result?
preg_replace('/(.*)(person|animal)(.*)/i', '$2$4', '123-ea-person.png');if you delete extension conditionstrtolower(preg_replace('/(.*)(person|animal)(.*)/i', '$2', '123-ea-person.jpg 456456-on-Person.jpg a-animal-dog.png'));preg_match('~\b(person|animal)\b~i', $str, $out)personoranimaloccur more than once in the string?