Complex pre_replace that uses a tempered-greedy token pattern

14 Views Asked by At

Suppose the HTML below:

<div class="lsd-search-filter lsd-col-10">
  <label for="lsd_search_10574_listdom-location">Regions</label>
  <div class="lsd-hierarchical-dropdowns" id="lsd_search_10574_listdom-location_wrapper" data-for="listdom-location" data-id="lsd_search_10574_listdom-location" data-max-levels="2" data-name="sf-listdom-location" data-hide-empty="0">
    <select class="listdom-location" name="sf-listdom-location" id="lsd_search_10574_listdom-location_1" placeholder="Select Region" data-level="1">
      <option value="">Select Region</option>
      <option class="lsd-option lsd-parent-0" value="289">Region 1</option>
      <option class="lsd-option lsd-parent-0" value="391">Region 2</option>
      <option class="lsd-option lsd-parent-0" value="290">Region 3</option>
    </select>
    <select class="listdom-location" name="" id="lsd_search_10574_listdom-location_2" placeholder="Select Region" data-level="2">
      <option value="">Select Region</option>
      <option class="lsd-option lsd-parent-289" value="291">Area 1</option>
      <option class="lsd-option lsd-parent-289" value="292">Area 2</option>
    </select>
  </div>
</div>

This is two select boxes that are generated by a mechanism, and with the use of some JS, based on the selection of the first region, you can choose among some areas of that region. But unfortunately the mechanism that produces that, sets the default value of both levels to "Select Region", while I want to make the default option for level 2 to be "Select Area".

I don't have control over the mechanism that creates that HTML at "calculation" level. I can only utilize a last-minute filter, in order to manipulate the already calculated HTML code. So, I created a regex to successfully choose the correct select.

Now what I need is to further improve it so that within the matched text, I need to change the two instances of "Select Region" to "Select Area".

Can you please help me achieve that?

TIA

0

There are 0 best solutions below