views:

21

answers:

2

I have a preg_replace taking out a part of a string it shouldn't be removing. It should be looking for: images_client/39/structure/party-2/ And replacing it with: images_client/39/structure/xxx/ It does do that, but it's also removing the images/ part of it just before apple_logo.jpg

 <?php 
    echo '<br>-------- preg_replace on a css string with slashes ------<br>';
    $string='/images_client/39/structure/party-2/images/apple_logo.jpg';
    echo 'Before: '.$string.'<br>';
    print preg_replace("/images_client\/39\/structure\/(\S+)\//", "images_client/39/structure/xxx/", $string) . "\n";
?>
A: 

Try this:

preg_replace('#images_client/39/structure/[^/]+/#s', 'images_client/39/structure/xxx/');
Crozin
Thank you, that worked out great!
EricP
A: 

Try [^/] instead of \S:

/images_client\/39\/structure\/([^\/]+)\//
Gumbo