0
<h3>Arlington</h3>
<div class="row Community">
    <div class="col-xs-3 text-nowrap">
        <strong><a href="/schedules/route/201-202">201/202</a></strong>
    </div>
    <div class="col-xs-8 col-xs-offset-1">Smokey Point to Lynnwood</div>
</div>
<div class="row Community">
    <div class="col-xs-3 text-nowrap">
        <strong><a href="/schedules/route/220">220</a></strong>
    </div>
    <div class="col-xs-8 col-xs-offset-1">Arlington to Smokey Point</div>
</div>
<div class="row Community">
    <div class="col-xs-3 text-nowrap">
        <strong><a href="/schedules/route/227">227</a></strong>
    </div>
    <div class="col-xs-8 col-xs-offset-1">Arlington to Seaway Transit Center</div>
</div>
<div class="row Community">
    <div class="col-xs-3 text-nowrap">
        <strong><a href="/schedules/route/230">230</a></strong>
    </div>
    <div class="col-xs-8 col-xs-offset-1">Darrington to Smokey Point</div>
</div>
<div class="row Community">
    <div class="col-xs-3 text-nowrap">
        <strong><a href="/schedules/route/240">240</a></strong>
    </div>
    <div class="col-xs-8 col-xs-offset-1">Stanwood to Smokey Point</div>
</div>

I'm currently trying to capture all of the <div class="row Community">...</div> blocks as separate groups. However, I'm running into the issue of it either only grouping the first div block or last div block depending on how I change my behavior.

This is the regex I've come up with:

<h3>A.*<\/h3>(\n\s*<div class="row Community">\n\s*<div class="col-xs-3 text-nowrap">\n\s*<strong><a href="(.*)<\/strong>\n\s*<\/div>\n\s*(.*)\n\s*<\/div>)*

But it's only returning, when I want all of the other ones as well:

<div class="row Community">
    <div class="col-xs-3 text-nowrap">
        <strong><a href="/schedules/route/240">240</a></strong>
    </div>
    <div class="col-xs-8 col-xs-offset-1">Stanwood to Smokey Point</div>
</div>
ThrowsError
  • 1,169
  • 1
  • 11
  • 43
henwin
  • 1
  • 2
  • 1
    Please read the canonical answer to all "parse HTML with regular expressions" questions. https://stackoverflow.com/a/1732454/25216 – Andrew Shepherd Feb 04 '21 at 01:11
  • 1
    Unofficially, we aren't "allowed" to answer such questions (because of [this post](https://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags)). You need to use a proper HTML parser to extract the data you want. Plenty of examples online about this. – costaparas Feb 04 '21 at 01:49

0 Answers0