0

I want to replace any html image tag that contains a specific string inside the "src" attribute.

Example:

<img id="IMG1" src="cid:[email protected]"/>

Should be replaced with "SOME STRING".

Images that contain a valid URL must not be replaced:

<img id="IMG1" src="http://someurl/image.png"/>

Can someone help me getting the correct regular expression for that?

EDIT: This one is my basic example but it replaces every image tag. I tried to get it on my own but unfortunately it didn't work:

preg_replace("/<img[^>]+\>/i", "SOME STRING", $myBaseString)

Thanks a lot.

Philip

2
  • 4
    What is the "specific string inside "src" attribute"? Commented Jul 18, 2014 at 9:30
  • I think to search for cid: would do it. Commented Jul 18, 2014 at 9:33

1 Answer 1

2

Regex:

(<img\b\s+.*?src=\")(.*?cid:.*?)(\">)

Replacement string:

\1SOME STRING\3

DEMO

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.