0

I've been trying to pass a large html piece containing lists with hyperlinks and their descriptions.

<li class="exhibitor-box">
    <figure>                        
    <img src="/images/show/logos/exhibitor_7210_letter.jpg" alt="Business Show Exhibitor">
    </figure>
    <h3 class="exhibitor-name"><a href="/exhibitors/financial-services/365-business-finance/">365 Business Finance</a></h3>
    <p>We provide funding to small and medium size businesses that take payment via credit cards.Our application process takes minutes, and you...</p>
</li>

And I've been attempting to grab the hyperlink descriptions from every list element, but I can only match the entire hyperlink with tag included using my regex, and even with regex how would I go about removing the text surrounding my match instead of replacing my match in notepad++.

Dan
  • 5,153
  • 4
  • 31
  • 42

2 Answers2

1

If all you want to do is replace the anchor tags with their inner text, you could do something like this:

Find what:

(<li class="exhibitor-box">.*?<a href=".*?">)(.*?)(</a>.*?</li>)

Replace with:

($2)

Explanation:

You're capturing everything from the li tag with a class of "exhibitor-box" in the first group up through the opening anchor tag in the first capture group, the link text in the second capture group, and the closing anchor tag through the closing li tag in the third capture group. You then replace these with only the second capture group.

Note that this is very ad-hoc - if your classes change you have to alter it a bit, if your HTML is inconsistently formatted from one li tag to the next it may not work, and it's assuming you only have one anchor tag per li tag.

Dan Field
  • 20,885
  • 5
  • 55
  • 71
  • How would I go about replacing the entire list element with the hyperlink description? – Jamal Abdisalam Apr 20 '15 at 16:08
  • Edited. Note that this is very ad-hoc and can't be relied on if your classes are different or you have weirdly/inconsistently (but validly) formatted `
  • ` elements.
  • – Dan Field Apr 20 '15 at 16:13