In JSON string I need to replace inconsistent values in multiple instances
String format to replace within each instance
inconsistent value 252/2022/08 to be replaced with consistent value 178/2023/03
{"url":"/wp-content/uploads/sites/252/2022/08/banner-rental.jpg",
Another instance may be. Note the difference with 06
{"url":"/wp-content/uploads/sites/252/2022/06/banner-swx.jpg",
The replacement value is passed by WordPress wp_upload_dir()['url'] which is /wp-content/uploads/sites/178/2023/03 stored in var $replace
method tried
preg_replace('#/wp-content/uploads/sites/(.*?)/#i',$replace,$jsondata);
The result is close but of course the stop point is at the first slash after sites/. I can't define the process to find and set the last slash as the end point.
{"url":"/wp-content/uploads/sites/178/2023/032022/06/banner-swx.jpg",
How can I find and set the last slash before the image name, as the ending point for the search?
.*. It is always a bad date? Maybe regex101.com/r/MOAiFK/1 works?from the pattern.