1

I have in a blog many links starting with https://mywebsite.com. I want to delete those links (but before /story1.html, /story2.html, etc, from the particular comments section

<!-- FLAGS1 --> <div class="cotarerField"> <div align="right">

<a href="https://mywebsite.com/story1.html"><img src="index_files/flag_lang_ro.jpg" title="ro" alt="ro" width="28" height="19" /></a>&nbsp; 
<a href="https://mywebsite.com/fr/story2.html"><img src="index_files/flag_lang_fr.jpg" title="fr" alt="fr" width="28" height="19" /></a>&nbsp; 
<a href="https://mywebsite.com/en/story3.html"><img src="index_files/flag_lang_en.jpg" title="en" alt="en" width="28" height="19" /></a>&nbsp; 
<a href="https://mywebsite.com/es/story4.html"><img src="index_files/flag_lang_es.jpg" title="es" alt="es" width="28" height="19" /></a>&nbsp; 
<a href="https://mywebsite.com/pt/story5.html"><img src="index_files/flag_lang_pt.jpg" title="pt" alt="pt" width="28" height="19" /></a>&nbsp; 
<a href="https://mywebsite.com/ar/story6.html"><img src="index_files/flag_lang_ae.jpg" width="28" height="19" title="ar" alt="ar" /></a>&nbsp; 
<a href="https://mywebsite.com/zh/story7.html"><img src="index_files/flag_lang_zh.jpg" width="28" height="19" title="zh" alt="zh" /></a>&nbsp; 
<a href="https://mywebsite.com/hi/story8.html"><img src="index_files/flag_lang_hi.jpg" width="28" height="19" title="hi" alt="hi" /></a>&nbsp; 
<a href="https://mywebsite.com/de/story9.html"><img src="index_files/flag_lang_de.jpg" width="28" height="19" title="de" alt="de" /></a>&nbsp; 
<a href="https://mywebsite.com/ru/story10.html"><img src="index_files/flag_lang_ru.jpg" width="28" height="19" title="ru" alt="ru" /></a>
</div>
<!-- FLAGS1 -->

or you can check here https://pastebin.com/Dtt3KjME

THE EXPECTED RESULT (delete all https://mywebsite.com/ )

<!-- FLAGS1 --> <div class="cotarerField"> <div align="right">

<a href="story1.html"><img src="index_files/flag_lang_ro.jpg" title="ro" alt="ro" width="28" height="19" /></a>&nbsp; 
<a href="fr/story2.html"><img src="index_files/flag_lang_fr.jpg" title="fr" alt="fr" width="28" height="19" /></a>&nbsp; 
<a href="en/story3.html"><img src="index_files/flag_lang_en.jpg" title="en" alt="en" width="28" height="19" /></a>&nbsp; 
<a href="es/story4.html"><img src="index_files/flag_lang_es.jpg" title="es" alt="es" width="28" height="19" /></a>&nbsp; 
<a href="pt/story5.html"><img src="index_files/flag_lang_pt.jpg" title="pt" alt="pt" width="28" height="19" /></a>&nbsp; 
<a href="ar/story6.html"><img src="index_files/flag_lang_ae.jpg" width="28" height="19" title="ar" alt="ar" /></a>&nbsp; 
<a href="zh/story7.html"><img src="index_files/flag_lang_zh.jpg" width="28" height="19" title="zh" alt="zh" /></a>&nbsp; 
<a href="hi/story8.html"><img src="index_files/flag_lang_hi.jpg" width="28" height="19" title="hi" alt="hi" /></a>&nbsp; 
<a href="de/story9.html"><img src="index_files/flag_lang_de.jpg" width="28" height="19" title="de" alt="de" /></a>&nbsp; 
<a href="ru/story10.html"><img src="index_files/flag_lang_ru.jpg" width="28" height="19" title="ru" alt="ru" /></a>
</div>
<!-- FLAGS1 -->
4
  • What is the expected result?
    – Toto
    Sep 28, 2019 at 10:21
  • Just Edit the topic, with the expected result
    – Just Me
    Sep 28, 2019 at 10:43
  • To be clear, you want to make the change ONLY between <!-- FLAGS1 --> and another <!-- FLAGS1 -->? Are there more <!-- FLAGS1 --> in the file?
    – Toto
    Sep 28, 2019 at 10:46
  • nope, only between <!-- FLAGS1 -->. Notice, that is not simple. Not just a simple search and delete, it must be only those links included in those 2 comments.
    – Just Me
    Sep 28, 2019 at 10:53

1 Answer 1

1
  • Ctrl+H
  • Find what: (?:\A[\s\S]*<!-- FLAGS1 -->|\G)(?:(?!<!-- FLAGS1 -->)[\s\S])+?\Khttps://mywebsite\.com/(?=[\s\S]*<!-- FLAGS1 -->)
  • Replace with: LEAVE EMPTY
  • check Wrap around
  • check Regular expression
  • Replace all

Explanation:

(?:                         # non capture group
  \A                        # beginning of file
  [\s\S]*                   # 0 or more any character
  <!-- FLAGS1 -->           # literally
 |                          # OR
  \G                        # restart from last match position
)                           # end group
(?:                         # non capture group (Tempered Greedy Token)
  (?!<!-- FLAGS1 -->)       # negative lookahead, make sure we haven't <!-- FLAGS1 -->
  [\s\S]                    # any character
)+?                         # end group, appears 1 or more times, not greedy
\K                          # forget all we have seen until this position
https://mywebsite\.com/     # text to be removed
(?=[\s\S]*<!-- FLAGS1 -->)  # positive lookahead, make sure we have <!-- FLAGS1 -->  after

Given:

<a href="https://mywebsite.com/ru/story10.html"><img src="index_files/flag_lang_ru.jpg" width="28" height="19" title="ru" alt="ru" /></a>

<!-- FLAGS1 --> <div class="cotarerField"> <div align="right">

<a href="https://mywebsite.com/story1.html"><img src="index_files/flag_lang_ro.jpg" title="ro" alt="ro" width="28" height="19" /></a>&nbsp; 
<a href="https://mywebsite.com/fr/story2.html"><img src="index_files/flag_lang_fr.jpg" title="fr" alt="fr" width="28" height="19" /></a>&nbsp; 
</div>

<!-- FLAGS1 -->

<a href="https://mywebsite.com/ru/story10.html"><img src="index_files/flag_lang_ru.jpg" width="28" height="19" title="ru" alt="ru" /></a>

Result for given example:

<a href="https://mywebsite.com/ru/story10.html"><img src="index_files/flag_lang_ru.jpg" width="28" height="19" title="ru" alt="ru" /></a>

<!-- FLAGS1 --> <div class="cotarerField"> <div align="right">

<a href="story1.html"><img src="index_files/flag_lang_ro.jpg" title="ro" alt="ro" width="28" height="19" /></a>&nbsp; 
<a href="fr/story2.html"><img src="index_files/flag_lang_fr.jpg" title="fr" alt="fr" width="28" height="19" /></a>&nbsp; 
</div>

<!-- FLAGS1 -->

<a href="https://mywebsite.com/ru/story10.html"><img src="index_files/flag_lang_ru.jpg" width="28" height="19" title="ru" alt="ru" /></a>

Screen capture (before):

enter image description here

Screen capture (after):

enter image description here

1
  • @JustMe: See my edit, now it replace only between FLAGs1 comment. Reason to use Non capture instead of capture group is this is more efficient (In case of you don't need to capture some part, of course)
    – Toto
    Sep 28, 2019 at 12:08

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .