Regular expresions to detect and remove links

So I want to do some in php, I get a text from wordpress that contains certain links, so what I want to do is first get all the files matching the following


And get a list of all the files on that text matching certain extensions. So basically the stuff in bold will repeat in every link I need to match, but the other thing will change, and I need a place to define the list of extensions for ext.

After that I need to remove from the text the matching link, meaninng:

<a href="matched_link" something> something</a>

Can some body help me with this.
Who is Participating?
Terry WoodsConnect With a Mentor IT GuruCommented:
Ok, something like this should match your links:


Open in new window

I'm a little unclear about what you want done for the big picture though. If you had text:

blah blah <a href="matched_link" something> something</a> blah

Did you want your result to be:
blah blah blah

Terry WoodsConnect With a Mentor IT GuruCommented:
If I understood your requirement correctly, this should do the trick:

Open in new window

Terry WoodsIT GuruCommented:
You should be able to see how I've allowed for multiple extensions by example. In my case I allowed jpg and gif. You can expand the list like this if you have an array of extensions:
$extensions = array("gif","jpg","etc");
$extensionPattern = implode("|",$extensions);

Open in new window

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.