# Regexp: Strip leading "../" from html image tags

**URL:** <https://forum.kirupa.com/t/regexp-strip-leading-from-html-image-tags/169489>\
**Category:** programming\
**Created:** [November 16, 2005, 5:53pm UTC](https://forum.kirupa.com/t/regexp-strip-leading-from-html-image-tags/169489 "2005-11-16T17:53:57Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![andr\_in](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/andr_in/32/37_2.png) [@andr\_in](https://forum.kirupa.com/u/andr_in)\
**Post date:** [November 16, 2005, 5:53pm UTC](https://forum.kirupa.com/t/regexp-strip-leading-from-html-image-tags/169489/1 "2005-11-16T17:53:57Z")

</div>

I need to strip the leading "…/"s from the src attribute of an html image tag.

For example:  
_\<img src="…/…/…/bar/foo.jpg" /\>_  
Should become  
_\<img src=“bar/foo.jpg” /\>_

This is what I came up with:

```php
preg_replace('#(<img.*?src=")[\./]*(.*?".*?>)#i', '$1$2', $text);

```

But it simply doesn’t work. I’m pulling my hair out over this one. :-/

Any suggestions?
