Hello,
I'm having a problem with regex backreferences. Now, I'm very close to solving my problem, but there is just one thing getting in the way. Here it is:
I have a pattern:
$pattern = '%(http://www\.[a-z]+\.[a-z]+/)(.*?)%';
This is supposed to match the first part of the URL as backreference 1, and the second part as backreference 2.
Let's look at an example URL:
http://www.example.org/images/moreimages/myfavoriteimage.jpg
Backreference 1 is:
http://www.example.org/
Backreference 2 is the rest of it:
images/moreimages/myfavoriteimage.jpg
However, when I do this:
$url2 = preg_replace($pattern, '$1', "http://www.example.org/images/moreimages/myfavoriteimage.jpg");
It matches and returns both backreferences instead of one! Why is it doing that?
Thanks.