Regex: Find all lines starting with a specific tag and ending with a different tag












1














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?










share|improve this question





























    1














    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?










    share|improve this question



























      1












      1








      1







      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?










      share|improve this question















      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






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Dec 19 '18 at 21:23

























      asked Dec 19 '18 at 21:03









      Just Me

      1818




      1818






















          2 Answers
          2






          active

          oldest

          votes


















          1














          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


          enter image description here






          share|improve this answer























          • 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










          • beautiful, thanks !
            – Just Me
            Dec 20 '18 at 13:57



















          0














          also, I find another answer:



          <p class="amigo">(?s)(?-s)(.*)<br>*$



          or



          <p class="amigo">(?-s)(.*)<br>*$






          share|improve this answer























          • (?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











          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
          });


          }
          });














          draft saved

          draft discarded


















          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









          1














          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


          enter image description here






          share|improve this answer























          • 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










          • beautiful, thanks !
            – Just Me
            Dec 20 '18 at 13:57
















          1














          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


          enter image description here






          share|improve this answer























          • 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










          • beautiful, thanks !
            – Just Me
            Dec 20 '18 at 13:57














          1












          1








          1






          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


          enter image description here






          share|improve this answer














          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


          enter image description here







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Dec 20 '18 at 13:54

























          answered Dec 20 '18 at 11:13









          Toto

          3,62391226




          3,62391226












          • 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










          • beautiful, thanks !
            – Just Me
            Dec 20 '18 at 13:57


















          • 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










          • beautiful, thanks !
            – Just Me
            Dec 20 '18 at 13:57
















          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












          beautiful, thanks !
          – Just Me
          Dec 20 '18 at 13:57




          beautiful, thanks !
          – Just Me
          Dec 20 '18 at 13:57













          0














          also, I find another answer:



          <p class="amigo">(?s)(?-s)(.*)<br>*$



          or



          <p class="amigo">(?-s)(.*)<br>*$






          share|improve this answer























          • (?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
















          0














          also, I find another answer:



          <p class="amigo">(?s)(?-s)(.*)<br>*$



          or



          <p class="amigo">(?-s)(.*)<br>*$






          share|improve this answer























          • (?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














          0












          0








          0






          also, I find another answer:



          <p class="amigo">(?s)(?-s)(.*)<br>*$



          or



          <p class="amigo">(?-s)(.*)<br>*$






          share|improve this answer














          also, I find another answer:



          <p class="amigo">(?s)(?-s)(.*)<br>*$



          or



          <p class="amigo">(?-s)(.*)<br>*$







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Dec 20 '18 at 16:38

























          answered Dec 20 '18 at 16:30









          Just 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


















          • (?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


















          draft saved

          draft discarded




















































          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.





          Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


          Please pay close attention to the following guidance:


          • 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%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





















































          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

          Probability when a professor distributes a quiz and homework assignment to a class of n students.

          Aardman Animations

          Are they similar matrix