Regex help for JMeter assertion

Let me preface by saying I know the problems inherent with trying to parse HTML with regex.

We're using JMeter for testing a new public site.  We have a variety of scenarios described, and I'm trying to make the tests as flexible as possible to avoid having them broken by future changes.  Towards that end, I'm using the regex extractor assertion to find the next link the test should follow.  In the target page's source, I have this structure:
<div class="u-odd">
  <a href="/senators/a-name-0">
    <div class="c-senator-block">
      <div class="nys-senator--thumb">
        <img src="/some-file.jpg" width="160" height="160" alt="" />
      </div>
      <div class="nys-senator--info">
        <h4 class="nys-senator--name">The Person's Name</h4>
        <span class="nys-senator--district">
          <span class="nys-senator--party">(GP)</span>
          District</span>
      </div>
    </div>
  </a>
</div>
<div class="u-even">
  <a href="/senators/another-name">
    <div class="c-senator-block">
      <div class="nys-senator--thumb">
        <img src="/some-file.jpg" width="160" height="160" alt="" />
      </div>
      <div class="nys-senator--info">
        <h4 class="nys-senator--name">Some Other Name</h4>
        <span class="nys-senator--district">
          <span class="nys-senator--party">(R)</span>
          District</span>
      </div>
    </div>
  </a>
</div>

Open in new window

There are dozens of blocks just like that, alternating between u-odd and u-even all the way down the page.  The target block is in the middle of the page.  I need to find the href associated with a particular name.

My last attempt used this pattern:
(?smi)<a[^>]*href="([^"]+)"(?!.*</a>)The Person's Name.*?</a>

Open in new window

Unfortunately, all of my attempts either pick up the very first href on the page, or nothing at all.  Can anyone provide some guidance on a pattern that will work for this?
LVL 51
Steve BinkAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

käµfm³d 👽Commented:
Out of what you posted above, what should be extracted/matched?
0
Steve BinkAuthor Commented:
The href attribute of the link.
0
käµfm³d 👽Commented:
I haven't played with JMeter extensively, but I know that it's built in Java, so I believe the following should work in JMeter as it does in other regex tools I use:

<a href="([^"]+)(?:[^<]|<(?!/a>))+?>The Person's Name

Open in new window


Capture group 1 has the href value.

Screenshot
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Steve BinkAuthor Commented:
That has the same results as some of my first tests - it picks up the href from the first link on the page.  

I've attached the entire body element so you have something more complete to test.  Picking up any single block under div.pane-senators would be sufficient.
senator-test-page.htm
0
käµfm³d 👽Commented:
Given the updated HTML sample, which specific href(s) are you after?
0
Steve BinkAuthor Commented:
Whichever href matches the name for which we are searching.  The name can change, depending on the test we need to run, but it will always be present in one of those blocks.  For now, try "Phil Boyle".
0
käµfm³d 👽Commented:
I'm afraid I'm not seeing the same behavior that you are:

Screenshot
0
Steve BinkAuthor Commented:
I see...  I had put only the last name as the search term.  I edited the regex to:
(?smi)<a href="([^"]+)"[^>]*>(?:[^<]|<(?!/a>))+?>[^<]*Boyle

Open in new window

That is picking up exactly what I want it to, and only requires the last name of the target.  Excellent!

Great work, käµfm³d 👽!
0
Steve BinkAuthor Commented:
BTW, what app are you using to test/build the regex?
0
käµfm³d 👽Commented:
Expresso. It's a .NET-based regex utility, but much of Java's and .NET's regexes are similar.
0
Steve BinkAuthor Commented:
Just needed a minor edit for an unstated, additional requirement.  Expert's solution was on the mark.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Regular Expressions

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.