How to write RegEx which starts and ends on different lines, these lines include one matching word only...












0















I want to replace a code group of 3 lines on the same file and on other fi
les by using notepad++ find & replace feature with regular expressions (regex)
Only thing in common on these lines which i want to select is they include the same word "mailicon4.gif" on the last line, and i want to select all the last line, and i want that the selection starts with "a class=" tag which comes 2-3 lines earlier. I copied the part i want to select with find and replace with "" to delete it.



I already tried such a code for example:
?maili.?$R



It selects the last paragraph but doesn't start with the last "


    <a class="nonblock nontext" id="u209382" href="mailto:info@example.com">
<!-- rasterized frame --><img class="temp_no_img_src" id="u209382_img" alt="" width="66" height="66"
data-orig-src="images/mailicon4-u209382.png?crc=143036675" src="images/mailicon4.gif?crc=4208392903" /></a>









share|improve this question























  • Can you make your target text more specific? It is somewhat vague/open right now.

    – Tim Biegeleisen
    Jan 1 at 11:06






  • 1





    Parsing HTML with regex is hard job HTML and regex are not good friends. Use a parser, it is simpler, faster and much more maintainable. See: php.net/manual/en/class.domdocument.php

    – Toto
    Jan 1 at 11:06











  • @TimBiegeleisen the code part, which i want to select and replace is exactly which i pasted above, i want my regex code capture all these 3 lines starting with "<a class=" and ends with "</a>" and only word in common is "maili" on the last line of these 3 lines

    – 0HE
    Jan 1 at 11:13
















0















I want to replace a code group of 3 lines on the same file and on other fi
les by using notepad++ find & replace feature with regular expressions (regex)
Only thing in common on these lines which i want to select is they include the same word "mailicon4.gif" on the last line, and i want to select all the last line, and i want that the selection starts with "a class=" tag which comes 2-3 lines earlier. I copied the part i want to select with find and replace with "" to delete it.



I already tried such a code for example:
?maili.?$R



It selects the last paragraph but doesn't start with the last "


    <a class="nonblock nontext" id="u209382" href="mailto:info@example.com">
<!-- rasterized frame --><img class="temp_no_img_src" id="u209382_img" alt="" width="66" height="66"
data-orig-src="images/mailicon4-u209382.png?crc=143036675" src="images/mailicon4.gif?crc=4208392903" /></a>









share|improve this question























  • Can you make your target text more specific? It is somewhat vague/open right now.

    – Tim Biegeleisen
    Jan 1 at 11:06






  • 1





    Parsing HTML with regex is hard job HTML and regex are not good friends. Use a parser, it is simpler, faster and much more maintainable. See: php.net/manual/en/class.domdocument.php

    – Toto
    Jan 1 at 11:06











  • @TimBiegeleisen the code part, which i want to select and replace is exactly which i pasted above, i want my regex code capture all these 3 lines starting with "<a class=" and ends with "</a>" and only word in common is "maili" on the last line of these 3 lines

    – 0HE
    Jan 1 at 11:13














0












0








0








I want to replace a code group of 3 lines on the same file and on other fi
les by using notepad++ find & replace feature with regular expressions (regex)
Only thing in common on these lines which i want to select is they include the same word "mailicon4.gif" on the last line, and i want to select all the last line, and i want that the selection starts with "a class=" tag which comes 2-3 lines earlier. I copied the part i want to select with find and replace with "" to delete it.



I already tried such a code for example:
?maili.?$R



It selects the last paragraph but doesn't start with the last "


    <a class="nonblock nontext" id="u209382" href="mailto:info@example.com">
<!-- rasterized frame --><img class="temp_no_img_src" id="u209382_img" alt="" width="66" height="66"
data-orig-src="images/mailicon4-u209382.png?crc=143036675" src="images/mailicon4.gif?crc=4208392903" /></a>









share|improve this question














I want to replace a code group of 3 lines on the same file and on other fi
les by using notepad++ find & replace feature with regular expressions (regex)
Only thing in common on these lines which i want to select is they include the same word "mailicon4.gif" on the last line, and i want to select all the last line, and i want that the selection starts with "a class=" tag which comes 2-3 lines earlier. I copied the part i want to select with find and replace with "" to delete it.



I already tried such a code for example:
?maili.?$R



It selects the last paragraph but doesn't start with the last "


    <a class="nonblock nontext" id="u209382" href="mailto:info@example.com">
<!-- rasterized frame --><img class="temp_no_img_src" id="u209382_img" alt="" width="66" height="66"
data-orig-src="images/mailicon4-u209382.png?crc=143036675" src="images/mailicon4.gif?crc=4208392903" /></a>






regex notepad++ regular-language






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Jan 1 at 11:01









0HE0HE

31




31













  • Can you make your target text more specific? It is somewhat vague/open right now.

    – Tim Biegeleisen
    Jan 1 at 11:06






  • 1





    Parsing HTML with regex is hard job HTML and regex are not good friends. Use a parser, it is simpler, faster and much more maintainable. See: php.net/manual/en/class.domdocument.php

    – Toto
    Jan 1 at 11:06











  • @TimBiegeleisen the code part, which i want to select and replace is exactly which i pasted above, i want my regex code capture all these 3 lines starting with "<a class=" and ends with "</a>" and only word in common is "maili" on the last line of these 3 lines

    – 0HE
    Jan 1 at 11:13



















  • Can you make your target text more specific? It is somewhat vague/open right now.

    – Tim Biegeleisen
    Jan 1 at 11:06






  • 1





    Parsing HTML with regex is hard job HTML and regex are not good friends. Use a parser, it is simpler, faster and much more maintainable. See: php.net/manual/en/class.domdocument.php

    – Toto
    Jan 1 at 11:06











  • @TimBiegeleisen the code part, which i want to select and replace is exactly which i pasted above, i want my regex code capture all these 3 lines starting with "<a class=" and ends with "</a>" and only word in common is "maili" on the last line of these 3 lines

    – 0HE
    Jan 1 at 11:13

















Can you make your target text more specific? It is somewhat vague/open right now.

– Tim Biegeleisen
Jan 1 at 11:06





Can you make your target text more specific? It is somewhat vague/open right now.

– Tim Biegeleisen
Jan 1 at 11:06




1




1





Parsing HTML with regex is hard job HTML and regex are not good friends. Use a parser, it is simpler, faster and much more maintainable. See: php.net/manual/en/class.domdocument.php

– Toto
Jan 1 at 11:06





Parsing HTML with regex is hard job HTML and regex are not good friends. Use a parser, it is simpler, faster and much more maintainable. See: php.net/manual/en/class.domdocument.php

– Toto
Jan 1 at 11:06













@TimBiegeleisen the code part, which i want to select and replace is exactly which i pasted above, i want my regex code capture all these 3 lines starting with "<a class=" and ends with "</a>" and only word in common is "maili" on the last line of these 3 lines

– 0HE
Jan 1 at 11:13





@TimBiegeleisen the code part, which i want to select and replace is exactly which i pasted above, i want my regex code capture all these 3 lines starting with "<a class=" and ends with "</a>" and only word in common is "maili" on the last line of these 3 lines

– 0HE
Jan 1 at 11:13












1 Answer
1






active

oldest

votes


















0
















  • Ctrl+F

  • Find what: <a (?:(?!</a>).)*mailicon4.gif.*?</a>

  • Replace with: $1 # a space then $1

  • check Wrap around

  • check Regular expression

  • CHECK . matches newline


Explanation:



<a                  # start tag
(?:(?!</a>).)* # 0 or more any character, but not </a>
mailicon4.gif # literally
.*? # 0 or more any character, not greedy
</a> # literally


Demo






share|improve this answer
























  • wonderful answer, thank you

    – 0HE
    Jan 1 at 20:49











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53994919%2fhow-to-write-regex-which-starts-and-ends-on-different-lines-these-lines-include%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0
















  • Ctrl+F

  • Find what: <a (?:(?!</a>).)*mailicon4.gif.*?</a>

  • Replace with: $1 # a space then $1

  • check Wrap around

  • check Regular expression

  • CHECK . matches newline


Explanation:



<a                  # start tag
(?:(?!</a>).)* # 0 or more any character, but not </a>
mailicon4.gif # literally
.*? # 0 or more any character, not greedy
</a> # literally


Demo






share|improve this answer
























  • wonderful answer, thank you

    – 0HE
    Jan 1 at 20:49
















0
















  • Ctrl+F

  • Find what: <a (?:(?!</a>).)*mailicon4.gif.*?</a>

  • Replace with: $1 # a space then $1

  • check Wrap around

  • check Regular expression

  • CHECK . matches newline


Explanation:



<a                  # start tag
(?:(?!</a>).)* # 0 or more any character, but not </a>
mailicon4.gif # literally
.*? # 0 or more any character, not greedy
</a> # literally


Demo






share|improve this answer
























  • wonderful answer, thank you

    – 0HE
    Jan 1 at 20:49














0












0








0









  • Ctrl+F

  • Find what: <a (?:(?!</a>).)*mailicon4.gif.*?</a>

  • Replace with: $1 # a space then $1

  • check Wrap around

  • check Regular expression

  • CHECK . matches newline


Explanation:



<a                  # start tag
(?:(?!</a>).)* # 0 or more any character, but not </a>
mailicon4.gif # literally
.*? # 0 or more any character, not greedy
</a> # literally


Demo






share|improve this answer















  • Ctrl+F

  • Find what: <a (?:(?!</a>).)*mailicon4.gif.*?</a>

  • Replace with: $1 # a space then $1

  • check Wrap around

  • check Regular expression

  • CHECK . matches newline


Explanation:



<a                  # start tag
(?:(?!</a>).)* # 0 or more any character, but not </a>
mailicon4.gif # literally
.*? # 0 or more any character, not greedy
</a> # literally


Demo







share|improve this answer












share|improve this answer



share|improve this answer










answered Jan 1 at 11:28









TotoToto

65.8k175698




65.8k175698













  • wonderful answer, thank you

    – 0HE
    Jan 1 at 20:49



















  • wonderful answer, thank you

    – 0HE
    Jan 1 at 20:49

















wonderful answer, thank you

– 0HE
Jan 1 at 20:49





wonderful answer, thank you

– 0HE
Jan 1 at 20:49




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53994919%2fhow-to-write-regex-which-starts-and-ends-on-different-lines-these-lines-include%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Monofisismo

Angular Downloading a file using contenturl with Basic Authentication

Olmecas