regex patterns



I’m having some problems with the eregi_replace() function. I can’t seem to get my regex pattern to match the text that I’m trying to replace. Is there anything obvious that’s causing the problem?

Here’s the patter:

$output = eregi_replace('<p class="submission">s*<a href="*/"><span class="shadow"><img src="[a-zA-Z0-9]*" width="d*" height="d*" alt=".*" /></span></a>s*</p>', '', $output);

And here’s an example of what I’m trying to match:

<p class="submission"> <a href=""><span class="shadow"><img src="" width="300" height="225" alt="" /></span></a> </p>

I’ve also tried this pattern to no avail:

$output = eregi_replace('(<a [^<]*href=["|']?([^ "']*)["|']?[^>].*>([^<]*)</a>)<span class="shadow"><img src="[^http://thumbs]" width="[0-9]" height="[0-9]" alt="[a-zA-Z0-9]" /></span></a>', '', $output);

Anyone see where I’m going wrong?


Just tried another pattern and my regex tester says that it makes a match but PHP returns a “REG_BADRPT” error. The pattern I came up with is as follows:

<p class="submission">s*<a href="*/"><span class="shadow"><img src="*/w*[a-z]*/d++/d+/d/[a-z]*/w*.w*" width="d*" height="d*" alt="[a-z0-9]*" /></span></a>s*</p>

I also tried escaping a few characters to no avail. Here’s what that led to:

<p class="submission">\s*<a href="http://www\.deviantart\.com/deviation/\d*/"><span class="shadow"><img src="http://thumbs\.deviantart\.com/\w*/\w*\.deviantart\.com/[a-z]*/\d++/\d+/\d/[a-z]*/\w*\.\w*" width="\d*" height="\d*" alt="[a-z0-9]*" /></span></a>\s*</p>


Right, yet another attemot and still no luck. This is the regex I have. It’s now valid (no errors) but doesn’t match the pattern referred to in my first post:

<p class="submission">s*<a href="*/"><span class="shadow"><img src="*/w*[a-z]*/d+/d+/d/[a-z]*/w*.w*" width="d*" height="d*" alt="[a-z0-9]*" /></span></a>s*</p>

Anyone have any ideas whatsoever?


Didn’t really bother to look through all those regexp’s, but try matching small parts of that code with small parts of the regex, that will help you determine which part exactly is the problem. If you absolutely can’t find the problem, then post back here with ONE regex and someone here can help fix it - posting a whole bunch of them doesn’t really help much lol.


Hey again

Thanks for looking anyway :slight_smile:


Check out the regex coach ( I love it!


i’ll have a look :) cheers