L
L
levisl2015-10-29 03:19:23
Regular Expressions
levisl, 2015-10-29 03:19:23

How to catch second, third, nth match in regexp?

There is such a page

Любимые регионы:

<div>Макрорегион</div>
<div><select name="favoriteRegionsPanel:panel:expandable-panel:macroRegionSelect" id="id578">
<option selected="selected" value="">Выберите значение</option>
<option value="0">МР Москва</option>
<option value="1">МР СЗ</option>
<option value="2">МР Юг</option>
<option value="3">МР Сибирь</option>
<option value="4">МР Урал</option>
<option value="5">МР ПСЗ</option>
<option value="6">МР ДВ</option>
<option value="7">МР ПЮВ</option>
</select></div>
</div>
<div>
<div>Регион</div>
<div><select id="id59a" style="display:none"></select></div>
</div>

</div>
</div>
</div>

</div>


<div class="clear">&nbsp;</div>

<div class="expandable-panel-level0">
<div class="expandable-panel-header-level0" id="id57b">
<img id="id59b" src="/images/tree-node-collapse.gif" alt="Раскрыть"/>
Региональные настройки:

<div>Макрорегион</div>
<div><select name="regionalSettingsPanel:panel:expandable-panel:macroRegionSelect" id="id57a">
<option selected="selected" value="">Выберите значение</option>
<option value="0">МР Москва</option>
<option value="1">МР СЗ</option>
<option value="2">МР Юг</option>
<option value="3">МР Сибирь</option>
<option value="4">МР Урал</option>
<option value="5">МР ПСЗ</option>
<option value="6">МР ДВ</option>
<option value="7">МР ПЮВ</option>

there is a regexp
<option value="(.*?)">МР ПЮВ</option>
It will catch me the value from the first part only. Is it possible to specify in the regular expression that he would take not the first, but a certain occurrence?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
lelvisl, 2015-10-29
@lelvisl

I dug it myself - FindAllStringSubmatch helped
https://play.golang.org/p/-IwYmNCVWD

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question