Regex: Find all lines starting with a specific tag and ending with a different tag
I want to Find all lines starting with a specific tag and ending with a different tag. For example:
<p class="amigo">My mother is at home.<br>
tried a regex, but doesn't work to good, because the selection does not stop at <br>
, it selects all after it, if I have more tags like this: .*<p class="amigo">(?s)(.*)<br>*$
Can anyone help me?
windows-10 notepad++ regex
add a comment |
I want to Find all lines starting with a specific tag and ending with a different tag. For example:
<p class="amigo">My mother is at home.<br>
tried a regex, but doesn't work to good, because the selection does not stop at <br>
, it selects all after it, if I have more tags like this: .*<p class="amigo">(?s)(.*)<br>*$
Can anyone help me?
windows-10 notepad++ regex
add a comment |
I want to Find all lines starting with a specific tag and ending with a different tag. For example:
<p class="amigo">My mother is at home.<br>
tried a regex, but doesn't work to good, because the selection does not stop at <br>
, it selects all after it, if I have more tags like this: .*<p class="amigo">(?s)(.*)<br>*$
Can anyone help me?
windows-10 notepad++ regex
I want to Find all lines starting with a specific tag and ending with a different tag. For example:
<p class="amigo">My mother is at home.<br>
tried a regex, but doesn't work to good, because the selection does not stop at <br>
, it selects all after it, if I have more tags like this: .*<p class="amigo">(?s)(.*)<br>*$
Can anyone help me?
windows-10 notepad++ regex
windows-10 notepad++ regex
edited Dec 19 '18 at 21:23
Just Me
asked Dec 19 '18 at 21:03
Just MeJust Me
1818
1818
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
Just make the wildcard not greedy:
<p class="amigo">(?s)(.*?)<br>
// here __^
Edit according to comment:
Ctrl+F
- Find what:
<p class="amigo">(?:(?!</?p).)*<br>
- UNcheck Match case
- check Wrap around
- check Regular expression
- CHECK
. matches newline
- Search in document
Explanation:
<p class="amigo"> # literally
(?: # start non capture group
(?!</?p) # negative lookahead, make sure we haven't "<p" or "</p"
. # 1 anycharacter
)* # end group, may appear 0 or more times
<br> # literally
not quite, if I have something like this, doesn't work, it selects all tags/lines.<p class="amigo">My mother is at home.</p>
<p class="amigo">My mother is at home.</p>
<p class="amigo">My mother is at home.<br>
– Just Me
Dec 20 '18 at 13:12
@JustMe: See my edit.
– Toto
Dec 20 '18 at 13:54
add a comment |
also, I find another answer:
<p class="amigo">(?s)(?-s)(.*)<br>*$
or
<p class="amigo">(?-s)(.*)<br>*$
(?s)
means "dot matches newline" and(?-s)
nmeans the opposite "dot doesn't match newline. So,(?s)(?-s)
is the same that(?-s)
for Notepad++ it is the same that "Uncheck dot matches newline". (un)check it depending if you want to match linebreak within the 2 tags.>*$
means 0 or more>
before end of line. It is useless here.
– Toto
Dec 20 '18 at 17:49
I didn't mention in my regex the option "dot match newline". I just test it, and works. Of course, you gave me an idea, so you get my vote. Test my regex, you will see that is working, even if something may seem strange :)
– Just Me
Dec 20 '18 at 20:00
Of course it works, I've just given you some tricks to get your regex more efficient and simpler.
– Toto
Dec 21 '18 at 9:43
hello, yes. But what exactly means "match new lines" ?
– Just Me
Dec 21 '18 at 12:01
It means that.
matches newline (r
,n
). The default behaviour is.
doesn't match newline.
– Toto
Dec 21 '18 at 12:36
|
show 1 more comment
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "3"
};
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%2fsuperuser.com%2fquestions%2f1386042%2fregex-find-all-lines-starting-with-a-specific-tag-and-ending-with-a-different-t%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
Just make the wildcard not greedy:
<p class="amigo">(?s)(.*?)<br>
// here __^
Edit according to comment:
Ctrl+F
- Find what:
<p class="amigo">(?:(?!</?p).)*<br>
- UNcheck Match case
- check Wrap around
- check Regular expression
- CHECK
. matches newline
- Search in document
Explanation:
<p class="amigo"> # literally
(?: # start non capture group
(?!</?p) # negative lookahead, make sure we haven't "<p" or "</p"
. # 1 anycharacter
)* # end group, may appear 0 or more times
<br> # literally
not quite, if I have something like this, doesn't work, it selects all tags/lines.<p class="amigo">My mother is at home.</p>
<p class="amigo">My mother is at home.</p>
<p class="amigo">My mother is at home.<br>
– Just Me
Dec 20 '18 at 13:12
@JustMe: See my edit.
– Toto
Dec 20 '18 at 13:54
add a comment |
Just make the wildcard not greedy:
<p class="amigo">(?s)(.*?)<br>
// here __^
Edit according to comment:
Ctrl+F
- Find what:
<p class="amigo">(?:(?!</?p).)*<br>
- UNcheck Match case
- check Wrap around
- check Regular expression
- CHECK
. matches newline
- Search in document
Explanation:
<p class="amigo"> # literally
(?: # start non capture group
(?!</?p) # negative lookahead, make sure we haven't "<p" or "</p"
. # 1 anycharacter
)* # end group, may appear 0 or more times
<br> # literally
not quite, if I have something like this, doesn't work, it selects all tags/lines.<p class="amigo">My mother is at home.</p>
<p class="amigo">My mother is at home.</p>
<p class="amigo">My mother is at home.<br>
– Just Me
Dec 20 '18 at 13:12
@JustMe: See my edit.
– Toto
Dec 20 '18 at 13:54
add a comment |
Just make the wildcard not greedy:
<p class="amigo">(?s)(.*?)<br>
// here __^
Edit according to comment:
Ctrl+F
- Find what:
<p class="amigo">(?:(?!</?p).)*<br>
- UNcheck Match case
- check Wrap around
- check Regular expression
- CHECK
. matches newline
- Search in document
Explanation:
<p class="amigo"> # literally
(?: # start non capture group
(?!</?p) # negative lookahead, make sure we haven't "<p" or "</p"
. # 1 anycharacter
)* # end group, may appear 0 or more times
<br> # literally
Just make the wildcard not greedy:
<p class="amigo">(?s)(.*?)<br>
// here __^
Edit according to comment:
Ctrl+F
- Find what:
<p class="amigo">(?:(?!</?p).)*<br>
- UNcheck Match case
- check Wrap around
- check Regular expression
- CHECK
. matches newline
- Search in document
Explanation:
<p class="amigo"> # literally
(?: # start non capture group
(?!</?p) # negative lookahead, make sure we haven't "<p" or "</p"
. # 1 anycharacter
)* # end group, may appear 0 or more times
<br> # literally
edited Dec 20 '18 at 13:54
answered Dec 20 '18 at 11:13
TotoToto
3,65391226
3,65391226
not quite, if I have something like this, doesn't work, it selects all tags/lines.<p class="amigo">My mother is at home.</p>
<p class="amigo">My mother is at home.</p>
<p class="amigo">My mother is at home.<br>
– Just Me
Dec 20 '18 at 13:12
@JustMe: See my edit.
– Toto
Dec 20 '18 at 13:54
add a comment |
not quite, if I have something like this, doesn't work, it selects all tags/lines.<p class="amigo">My mother is at home.</p>
<p class="amigo">My mother is at home.</p>
<p class="amigo">My mother is at home.<br>
– Just Me
Dec 20 '18 at 13:12
@JustMe: See my edit.
– Toto
Dec 20 '18 at 13:54
not quite, if I have something like this, doesn't work, it selects all tags/lines.
<p class="amigo">My mother is at home.</p>
<p class="amigo">My mother is at home.</p>
<p class="amigo">My mother is at home.<br>
– Just Me
Dec 20 '18 at 13:12
not quite, if I have something like this, doesn't work, it selects all tags/lines.
<p class="amigo">My mother is at home.</p>
<p class="amigo">My mother is at home.</p>
<p class="amigo">My mother is at home.<br>
– Just Me
Dec 20 '18 at 13:12
@JustMe: See my edit.
– Toto
Dec 20 '18 at 13:54
@JustMe: See my edit.
– Toto
Dec 20 '18 at 13:54
add a comment |
also, I find another answer:
<p class="amigo">(?s)(?-s)(.*)<br>*$
or
<p class="amigo">(?-s)(.*)<br>*$
(?s)
means "dot matches newline" and(?-s)
nmeans the opposite "dot doesn't match newline. So,(?s)(?-s)
is the same that(?-s)
for Notepad++ it is the same that "Uncheck dot matches newline". (un)check it depending if you want to match linebreak within the 2 tags.>*$
means 0 or more>
before end of line. It is useless here.
– Toto
Dec 20 '18 at 17:49
I didn't mention in my regex the option "dot match newline". I just test it, and works. Of course, you gave me an idea, so you get my vote. Test my regex, you will see that is working, even if something may seem strange :)
– Just Me
Dec 20 '18 at 20:00
Of course it works, I've just given you some tricks to get your regex more efficient and simpler.
– Toto
Dec 21 '18 at 9:43
hello, yes. But what exactly means "match new lines" ?
– Just Me
Dec 21 '18 at 12:01
It means that.
matches newline (r
,n
). The default behaviour is.
doesn't match newline.
– Toto
Dec 21 '18 at 12:36
|
show 1 more comment
also, I find another answer:
<p class="amigo">(?s)(?-s)(.*)<br>*$
or
<p class="amigo">(?-s)(.*)<br>*$
(?s)
means "dot matches newline" and(?-s)
nmeans the opposite "dot doesn't match newline. So,(?s)(?-s)
is the same that(?-s)
for Notepad++ it is the same that "Uncheck dot matches newline". (un)check it depending if you want to match linebreak within the 2 tags.>*$
means 0 or more>
before end of line. It is useless here.
– Toto
Dec 20 '18 at 17:49
I didn't mention in my regex the option "dot match newline". I just test it, and works. Of course, you gave me an idea, so you get my vote. Test my regex, you will see that is working, even if something may seem strange :)
– Just Me
Dec 20 '18 at 20:00
Of course it works, I've just given you some tricks to get your regex more efficient and simpler.
– Toto
Dec 21 '18 at 9:43
hello, yes. But what exactly means "match new lines" ?
– Just Me
Dec 21 '18 at 12:01
It means that.
matches newline (r
,n
). The default behaviour is.
doesn't match newline.
– Toto
Dec 21 '18 at 12:36
|
show 1 more comment
also, I find another answer:
<p class="amigo">(?s)(?-s)(.*)<br>*$
or
<p class="amigo">(?-s)(.*)<br>*$
also, I find another answer:
<p class="amigo">(?s)(?-s)(.*)<br>*$
or
<p class="amigo">(?-s)(.*)<br>*$
edited Dec 20 '18 at 16:38
answered Dec 20 '18 at 16:30
Just MeJust Me
1818
1818
(?s)
means "dot matches newline" and(?-s)
nmeans the opposite "dot doesn't match newline. So,(?s)(?-s)
is the same that(?-s)
for Notepad++ it is the same that "Uncheck dot matches newline". (un)check it depending if you want to match linebreak within the 2 tags.>*$
means 0 or more>
before end of line. It is useless here.
– Toto
Dec 20 '18 at 17:49
I didn't mention in my regex the option "dot match newline". I just test it, and works. Of course, you gave me an idea, so you get my vote. Test my regex, you will see that is working, even if something may seem strange :)
– Just Me
Dec 20 '18 at 20:00
Of course it works, I've just given you some tricks to get your regex more efficient and simpler.
– Toto
Dec 21 '18 at 9:43
hello, yes. But what exactly means "match new lines" ?
– Just Me
Dec 21 '18 at 12:01
It means that.
matches newline (r
,n
). The default behaviour is.
doesn't match newline.
– Toto
Dec 21 '18 at 12:36
|
show 1 more comment
(?s)
means "dot matches newline" and(?-s)
nmeans the opposite "dot doesn't match newline. So,(?s)(?-s)
is the same that(?-s)
for Notepad++ it is the same that "Uncheck dot matches newline". (un)check it depending if you want to match linebreak within the 2 tags.>*$
means 0 or more>
before end of line. It is useless here.
– Toto
Dec 20 '18 at 17:49
I didn't mention in my regex the option "dot match newline". I just test it, and works. Of course, you gave me an idea, so you get my vote. Test my regex, you will see that is working, even if something may seem strange :)
– Just Me
Dec 20 '18 at 20:00
Of course it works, I've just given you some tricks to get your regex more efficient and simpler.
– Toto
Dec 21 '18 at 9:43
hello, yes. But what exactly means "match new lines" ?
– Just Me
Dec 21 '18 at 12:01
It means that.
matches newline (r
,n
). The default behaviour is.
doesn't match newline.
– Toto
Dec 21 '18 at 12:36
(?s)
means "dot matches newline" and (?-s)
nmeans the opposite "dot doesn't match newline. So, (?s)(?-s)
is the same that (?-s)
for Notepad++ it is the same that "Uncheck dot matches newline". (un)check it depending if you want to match linebreak within the 2 tags. >*$
means 0 or more >
before end of line. It is useless here.– Toto
Dec 20 '18 at 17:49
(?s)
means "dot matches newline" and (?-s)
nmeans the opposite "dot doesn't match newline. So, (?s)(?-s)
is the same that (?-s)
for Notepad++ it is the same that "Uncheck dot matches newline". (un)check it depending if you want to match linebreak within the 2 tags. >*$
means 0 or more >
before end of line. It is useless here.– Toto
Dec 20 '18 at 17:49
I didn't mention in my regex the option "dot match newline". I just test it, and works. Of course, you gave me an idea, so you get my vote. Test my regex, you will see that is working, even if something may seem strange :)
– Just Me
Dec 20 '18 at 20:00
I didn't mention in my regex the option "dot match newline". I just test it, and works. Of course, you gave me an idea, so you get my vote. Test my regex, you will see that is working, even if something may seem strange :)
– Just Me
Dec 20 '18 at 20:00
Of course it works, I've just given you some tricks to get your regex more efficient and simpler.
– Toto
Dec 21 '18 at 9:43
Of course it works, I've just given you some tricks to get your regex more efficient and simpler.
– Toto
Dec 21 '18 at 9:43
hello, yes. But what exactly means "match new lines" ?
– Just Me
Dec 21 '18 at 12:01
hello, yes. But what exactly means "match new lines" ?
– Just Me
Dec 21 '18 at 12:01
It means that
.
matches newline (r
,n
). The default behaviour is .
doesn't match newline.– Toto
Dec 21 '18 at 12:36
It means that
.
matches newline (r
,n
). The default behaviour is .
doesn't match newline.– Toto
Dec 21 '18 at 12:36
|
show 1 more comment
Thanks for contributing an answer to Super User!
- 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%2fsuperuser.com%2fquestions%2f1386042%2fregex-find-all-lines-starting-with-a-specific-tag-and-ending-with-a-different-t%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