How to write RegEx which starts and ends on different lines, these lines include one matching word only...
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
add a comment |
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
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
add a comment |
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
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
regex notepad++ regular-language
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
add a comment |
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
add a comment |
1 Answer
1
active
oldest
votes
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
wonderful answer, thank you
– 0HE
Jan 1 at 20:49
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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
wonderful answer, thank you
– 0HE
Jan 1 at 20:49
add a comment |
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
wonderful answer, thank you
– 0HE
Jan 1 at 20:49
add a comment |
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
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
answered Jan 1 at 11:28
TotoToto
65.8k175698
65.8k175698
wonderful answer, thank you
– 0HE
Jan 1 at 20:49
add a comment |
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
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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