arled
arled

Reputation: 2690

Get particular <a> tags that have a specific href

My regex skills are a bit rusty. I'm developing in PHP and I'm trying to use regex to extract certain tags that have a specific href, i.e:

    <a href=”javascript:void(0);” onclick=”window.open('.some-thing/utilities/words/hello','Words','
    toolbar=no,location=no,status=no,menubar=no,scrollbars=yes'); 
    return false;”>Hello</a>

    <a href=”www.google.com”>Google</a>

How can I extract one tags that contain href=”javascript:void(0);”? Hope that makes sense. I could provide example of my regex used but I have used so many and they're just to messy.

Upvotes: 0

Views: 62

Answers (1)

zessx
zessx

Reputation: 68790

Warning: you shouldn't parse HTML with a regex


For the whole link:

/(<a\s[^>]*?href="javascript:void\(0\)\;?"[^>]*?>.*?<\/a>)/gsi

For content only:

/<a\s[^>]*?href="javascript:void\(0\)\;?"[^>]*?>(.*?)<\/a>/gsi


Try it yourself

Upvotes: 1

Related Questions