Reputation: 115
In the string:
$text = 'The quick brown fox jumps over the lazy dog';
How can I preg_replace all except "fox"?
Something like:
$new = preg_replace('(.*?)|^[fox]|(.*?)si', '', $text);
Note:
I'm looking for a preg_replace() solution, not explode() or preg_match_all().
Thanks for any help!
Upvotes: 0
Views: 3233
Reputation: 91428
Not I well understand your need, but how about:
$new = preg_replace('/^.*?(fox).*?$/si', '$1', $text);
Upvotes: 1
Reputation: 31005
You can use this regex to grab the path/whatever
as you pointed.
(path\/[^\[\]\s]+)
What I'm not clear about is related to your output string since you put:
"path/file1.txtpath/file2.jpg[/imgpath/file3 to a [i"
My regex would help you to generate:
"path/file1.txtpath/file2.jpgpath/file3"
Can you confirm is above is ok?
Upvotes: 0