I got this sting that I would like to match in these anchor links I mean preg_replace but leave anchor text:
/gente/huelva
<a href="somesite.com/gente/huelva">Huelva</a>
<a href="somesite.com/gente/huelva?language_id=1">Huelva</a>
Don’t match if dash is found like this huelva-
Match if huelva?language_id=1
or
huelva/?language_id=1
RegEX that seems to be working:
<a href="https:\/\/www\.mysite\.com\b(\/gente\/huelva)\b(?<!-)">([^>]*)<\/a>
Well, the pattern you’ve given does not match the links you’ve given, even if I fix the front end.
There is no \b present on the front end.
What you appear to be trying to do is:
<a href="https:\/\/www\.mysite\.com(\/gente\/huelva)(\?.*?)?">([^>]*?)<\/a>
Thanks buddy so this wont work:
preg_replace('#<a href=".*?\b(\/gente\/huelva)\b">([^>]*)<\/a>#i', '$2', '<a href="https://www.site.com/gente/huelva">Huelva</a>');
So the idea is to replace a single link with the text “/gente/huelva”?
preg_replace('#<a href=".*?\b(\/gente\/huelva)(\?.*?)?">([^<]*)<\/a>#i', '$2', '<a href="https://www.site.com/gente/huelva">Huelva</a>');
I’d like to replace it with Huelva anchor link text.
$3 then, cause we introduced a new subpattern.
OK thanks so much buddy for your support.
rpkamp
June 17, 2018, 7:47pm
8
<off-topic>
Did you know you can make matching groups non-capturing? Just start with ?:
, i.e., (?:\/gente\/huelva)
That will match, but it will not be available in the replacements and it’s place will not be reserved.
Handy for when you need an capture group but you’re interested in what’s actually in there.
</off-topic>
system
Closed
September 17, 2018, 2:47am
9
This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.