What would the regular expression be for removing any content between a quote, and the directory “uploads/”?
Using a regexpression generator, I get this: (?<=\=”)^+?(?=uploads/)
$block_data = preg_replace('/(?<=\=")^+?(?=uploads/)/g','',$block_data);
But seems to be removing everything 🙁
,
You should escape the “/” in “uploads/” and g
isn’t a valid modifier, plus ^
is invalid, I guess you wanted .
instead.
Here is your regex :
/(?<=\=").+?(?=uploads\/)/
The test on ideone
,
The simple solution would be
$block_data = preg_replace('/(?<=").*?(?=uploads\/)/','',$block_data);
Changes made:
- Simplified your lookbehind and lookahead assertions
- escaped the
/
in the lookahead - removed the
g
modifier, which is unnecessary in PHP
This works, so far as I can tell, reducing first"middle/uploads/end"
to first"uploads/end"
.