I am looking for a regular expression in PHP to extract the links a text that contain the specific words (apple, home, car) in the text of anchor.
Important: the formatting of links is not known in advance.
E.g:
<a href="fruit.html">The Apple red</a>
<a href="Construction.html#one">The big Home</a>
<a href="automotive.html?lang=en">Car for rent</a>
Desired result:
fruit.html
Construction.html#one
automotive.html?lang=en
My pattern:
/<a.*?href="(.*)".*?>apple|car|home<\/a>/i
Update: This pattern works
'/<a.+href=["\'](.*)["\'].*>(.*(?:apple|car|home).*)<\/a>/iU'