Got more questions? Find advice on: ASP | SQL | XML | Windows
in Search
Welcome to RegexAdvice Sign in | Join | Help

Find hyperlinks that contain a specific word?

Last post 07-30-2010, 11:14 AM by BMAN645. 4 replies.
Sort Posts: Previous Next
  •  07-29-2010, 7:13 PM 70242

    Find hyperlinks that contain a specific word?

    Hi everyone!

    I'm trying to figure out how to write a regular expression that can find a hyperlink that contains a specific word somewhere in the link.

    For example, lets say the word is "Product". It should find links like <a href="Products.html"> OR <a href="Product_List.php"> but NOT links like <a href="SomeOtherPage.html">, of course.

    I found out how to use Regex to find regular hyperlinks by using href="(?<Link>.*?)"

    But I don't know how to make it find hyperlinks that contain a specific word.

    So, any regex pros out there know how to do this?

     Thanks!

  •  07-29-2010, 8:14 PM 70245 in reply to 70242

    Re: Find hyperlinks that contain a specific word?

    Try:

    href="(?<Link>((?!"|product).)*product.*?)" 

    with the 'ignore case' option set.

    What this does is to replace the '.*?' with '((?!"|product).)*' which is a specific test for 2 conditions: either the double-quote character (which means the attribute value does NOT contain the character sequence "product") or the "product" sequence.

    The part requires a match with the "product" characters and so will reject any match that is with a value that does not contain this sequence. As there is a single criteria for ending the attribute value (the next double-quote), the '.*?' can be used to complete the match.

    By the way, can you please read the posting guidelines in the sticky note at the beginning of this forum and provide as much of the requested information as possible. While the pattern I have suggested should work on most regex variants, I can't be certain about whatever one you are using as I don't know what it is!

    Susan

  •  07-29-2010, 8:40 PM 70247 in reply to 70245

    Re: Find hyperlinks that contain a specific word?

    Hi Susan,

    That works great! Thanks so much for your help  ( - :

    BTW- The program I am using for this (WinAutomation) doesn't mention what regex variant it uses, so that's why I left that part out.

    Anyways, thanks again!

  •  07-30-2010, 11:02 AM 70288 in reply to 70247

    Re: Find hyperlinks that contain a specific word?

    BMAN645:

    Hi Susan,

    That works great! Thanks so much for your help  ( - :

    BTW- The program I am using for this (WinAutomation) doesn't mention what regex variant it uses, so that's why I left that part out.

    Anyways, thanks again!

    That is why we ask you tell us the application you are using so we can determine which variation of regular expressions are being used or at least see which features are supported


    Michael

    "In theory, theory and practice are the same. In practice, they are not."
    Albert Einstein
  •  07-30-2010, 11:14 AM 70291 in reply to 70288

    Re: Find hyperlinks that contain a specific word?

    Thanks Michael, will do next time!
View as RSS news feed in XML