regex patterns


#1

Hey

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="http://www.deviantart.com/deviation/d*/"><span class="shadow"><img src="http://thumbs.deviantart.com/[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="http://www.deviantart.com/deviation/9854054/"><span class="shadow"><img src="http://thumbs.deviantart.com/300W/fs4.deviantart.com/i/2004/230/6/f/peurto_rico_flowers_two.jpg" 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?


#2

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="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>

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>

#3

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="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>

Anyone have any ideas whatsoever?


#4

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.


#5

Hey again

Thanks for looking anyway :slight_smile:


#6

Check out the regex coach (http://www.weitz.de/regex-coach/). I love it!


#7

i’ll have a look :) cheers