2019-12-30

Regex replace only open tag of html, concat new line as prefix of matched string.



https://stackoverflow.com/questions/14458160/while-replacing-using-regex-how-to-keep-a-part-of-matched-string

Using this:
Search for: <([^/])
Replace by: \r\n<\1

Key is the grouping bracket, () in "Search for:", and \1 in "Replace by:"


https://www.mymesra.com.my/gas-petronas-dealer-locator.aspx


Turn below:

<div class="infoBox" style="background: rgb(255, 255, 255); opacity: 1; width: 314px; border: 3px solid rgb(47, 47, 47); padding: 0px; position: absolute; visibility: visible; left: -121.946px; top: -82.0625px;"><img src="img/petrolstation/close.gif" align="right" style=" position: relative; cursor: pointer; margin: 5px 5px 0 0;"><div class="info-window"><div class="info-inner"><div class="info-title">SETI ROHAYAH KASMANI ENTERPRISE</div><div class="info-address">NO.15, JALAN GELANG EMAS 1, TAMAN GELANG EMAS, 81550 GELANG PATAH, JOHOR</div><div class="info-tel"><b>Please Call:</b><br><b>Tel: </b><span class="gas-tel">-</span><br><b>Mobile No: </b><span class="gas-mobile"><a href="tel://016-757 6549">016-757 6549</a></span></div></div><div class="info-direction"><a onclick="window.location.href=this.href;return false;" class="link-btn lb-regular lb-direction-btn" href="javascript:GetDirection(1692,'68, Jalan Laman Setia 3/10', 'NO.15, JALAN GELANG EMAS 1, TAMAN GELANG EMAS, 81550 GELANG PATAH, JOHOR, 81550 GELANG PATAH (1.451778, 103.585300)', '1.451778, 103.585300');">Get Directions</a></div><div class="info-disclaimer"><b>Note:</b><br>Delivery arrangement shall be made directly with our dealers based on mutually agreed delivery time and charges.</div></div></div>

Into:

<div class="infoBox" style="background: rgb(255, 255, 255); opacity: 1; width: 314px; border: 3px solid rgb(47, 47, 47); padding: 0px; position: absolute; visibility: visible; left: -121.946px; top: -82.0625px;">
<img src="img/petrolstation/close.gif" align="right" style=" position: relative; cursor: pointer; margin: 5px 5px 0 0;">
<div class="info-window">
<div class="info-inner">
<div class="info-title">SETI ROHAYAH KASMANI ENTERPRISE</div>
<div class="info-address">NO.15, JALAN GELANG EMAS 1, TAMAN GELANG EMAS, 81550 GELANG PATAH, JOHOR</div>
<div class="info-tel">
<b>Please Call:</b>
<br>
<b>Tel: </b>
<span class="gas-tel">-</span>
<br>
<b>Mobile No: </b>
<span class="gas-mobile">
<a href="tel://016-757 6549">016-757 6549</a></span></div></div>
<div class="info-direction">
<a onclick="window.location.href=this.href;return false;" class="link-btn lb-regular lb-direction-btn" href="javascript:GetDirection(1692,'68, Jalan Laman Setia 3/10', 'NO.15, JALAN GELANG EMAS 1, TAMAN GELANG EMAS, 81550 GELANG PATAH, JOHOR, 81550 GELANG PATAH (1.451778, 103.585300)', '1.451778, 103.585300');">Get Directions</a></div>
<div class="info-disclaimer">
<b>Note:</b>
<br>Delivery arrangement shall be made directly with our dealers based on mutually agreed delivery time and charges.</div></div></div>