problem understaning /.*/

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;







up vote
0
down vote

favorite












I have problem understanding /.*/ according to things written in books, this prints the entire line of the text. we know that. means any character, and * means zero or more occurrence of the preceding character. so I expect that /.*/ finds something like rrr qqqq abbbbb, I mean continuouslynuesly repetition of a single character.



but this is not the thing it does. why?



my second question is: why /.+/ doesn't do the same thing?? in the text I'm trying on the result is ?







share|improve this question

























    up vote
    0
    down vote

    favorite












    I have problem understanding /.*/ according to things written in books, this prints the entire line of the text. we know that. means any character, and * means zero or more occurrence of the preceding character. so I expect that /.*/ finds something like rrr qqqq abbbbb, I mean continuouslynuesly repetition of a single character.



    but this is not the thing it does. why?



    my second question is: why /.+/ doesn't do the same thing?? in the text I'm trying on the result is ?







    share|improve this question





















      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      I have problem understanding /.*/ according to things written in books, this prints the entire line of the text. we know that. means any character, and * means zero or more occurrence of the preceding character. so I expect that /.*/ finds something like rrr qqqq abbbbb, I mean continuouslynuesly repetition of a single character.



      but this is not the thing it does. why?



      my second question is: why /.+/ doesn't do the same thing?? in the text I'm trying on the result is ?







      share|improve this question











      I have problem understanding /.*/ according to things written in books, this prints the entire line of the text. we know that. means any character, and * means zero or more occurrence of the preceding character. so I expect that /.*/ finds something like rrr qqqq abbbbb, I mean continuouslynuesly repetition of a single character.



      but this is not the thing it does. why?



      my second question is: why /.+/ doesn't do the same thing?? in the text I'm trying on the result is ?









      share|improve this question










      share|improve this question




      share|improve this question









      asked yesterday









      Fatemeh Karimi

      1154




      1154




















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          3
          down vote



          accepted










          No, the * in .* means "any number of the preceding expression", i.e. zero or more of whatever character that matches the expression ..



          This means that .* will match aaaa as well as abcd since all of the characters in abcd matches .. It will also match an empty line, since it allows for zero matches.



          If you'd like to find a line that contains a repeated character, use



          /(.)11*/


          This expression matches "any character, then the same character, and then any number of more of the same character". The 1* could arguably be removed unless you're looking for lines that contain only a repeated character, in which case you should anchor the expression to the start and end of the line, as in



          /^(.)11*$/


          The ed editor supports basic regular expressions. The + modifier is an extended regular expression modifier. The ? that you get from ed when using /.+/ would be followed by no match (or No match in GNU ed) if you had enabled error explanations with the H command. This is because it tries to find a line with a + in it, preceded by some other character.



          The .+ extended regular expression ("match one or more of any character") is equivalent to the basic regular expression ..*, i.e. "match a character, and then zero or more of any character".



          According to its manual, GNU ed should support + in regular expressions, so that ..* is equivalent to .+, but GNU ed 1.14.2 on my OpenBSD system does not do this.






          share|improve this answer



















          • 1




            Even if the * referred to copies of the same character, it matches zero or more, so it would still match on any line since a zero amount of something is really easy to find...
            – ilkkachu
            yesterday






          • 1




            Great work and congrats on the 100K!
            – Stephen Rauch
            yesterday










          Your Answer







          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "106"
          ;
          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',
          convertImagesToLinks: false,
          noModals: false,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );








           

          draft saved


          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f460619%2fproblem-understaning%23new-answer', 'question_page');

          );

          Post as a guest






























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          3
          down vote



          accepted










          No, the * in .* means "any number of the preceding expression", i.e. zero or more of whatever character that matches the expression ..



          This means that .* will match aaaa as well as abcd since all of the characters in abcd matches .. It will also match an empty line, since it allows for zero matches.



          If you'd like to find a line that contains a repeated character, use



          /(.)11*/


          This expression matches "any character, then the same character, and then any number of more of the same character". The 1* could arguably be removed unless you're looking for lines that contain only a repeated character, in which case you should anchor the expression to the start and end of the line, as in



          /^(.)11*$/


          The ed editor supports basic regular expressions. The + modifier is an extended regular expression modifier. The ? that you get from ed when using /.+/ would be followed by no match (or No match in GNU ed) if you had enabled error explanations with the H command. This is because it tries to find a line with a + in it, preceded by some other character.



          The .+ extended regular expression ("match one or more of any character") is equivalent to the basic regular expression ..*, i.e. "match a character, and then zero or more of any character".



          According to its manual, GNU ed should support + in regular expressions, so that ..* is equivalent to .+, but GNU ed 1.14.2 on my OpenBSD system does not do this.






          share|improve this answer



















          • 1




            Even if the * referred to copies of the same character, it matches zero or more, so it would still match on any line since a zero amount of something is really easy to find...
            – ilkkachu
            yesterday






          • 1




            Great work and congrats on the 100K!
            – Stephen Rauch
            yesterday














          up vote
          3
          down vote



          accepted










          No, the * in .* means "any number of the preceding expression", i.e. zero or more of whatever character that matches the expression ..



          This means that .* will match aaaa as well as abcd since all of the characters in abcd matches .. It will also match an empty line, since it allows for zero matches.



          If you'd like to find a line that contains a repeated character, use



          /(.)11*/


          This expression matches "any character, then the same character, and then any number of more of the same character". The 1* could arguably be removed unless you're looking for lines that contain only a repeated character, in which case you should anchor the expression to the start and end of the line, as in



          /^(.)11*$/


          The ed editor supports basic regular expressions. The + modifier is an extended regular expression modifier. The ? that you get from ed when using /.+/ would be followed by no match (or No match in GNU ed) if you had enabled error explanations with the H command. This is because it tries to find a line with a + in it, preceded by some other character.



          The .+ extended regular expression ("match one or more of any character") is equivalent to the basic regular expression ..*, i.e. "match a character, and then zero or more of any character".



          According to its manual, GNU ed should support + in regular expressions, so that ..* is equivalent to .+, but GNU ed 1.14.2 on my OpenBSD system does not do this.






          share|improve this answer



















          • 1




            Even if the * referred to copies of the same character, it matches zero or more, so it would still match on any line since a zero amount of something is really easy to find...
            – ilkkachu
            yesterday






          • 1




            Great work and congrats on the 100K!
            – Stephen Rauch
            yesterday












          up vote
          3
          down vote



          accepted







          up vote
          3
          down vote



          accepted






          No, the * in .* means "any number of the preceding expression", i.e. zero or more of whatever character that matches the expression ..



          This means that .* will match aaaa as well as abcd since all of the characters in abcd matches .. It will also match an empty line, since it allows for zero matches.



          If you'd like to find a line that contains a repeated character, use



          /(.)11*/


          This expression matches "any character, then the same character, and then any number of more of the same character". The 1* could arguably be removed unless you're looking for lines that contain only a repeated character, in which case you should anchor the expression to the start and end of the line, as in



          /^(.)11*$/


          The ed editor supports basic regular expressions. The + modifier is an extended regular expression modifier. The ? that you get from ed when using /.+/ would be followed by no match (or No match in GNU ed) if you had enabled error explanations with the H command. This is because it tries to find a line with a + in it, preceded by some other character.



          The .+ extended regular expression ("match one or more of any character") is equivalent to the basic regular expression ..*, i.e. "match a character, and then zero or more of any character".



          According to its manual, GNU ed should support + in regular expressions, so that ..* is equivalent to .+, but GNU ed 1.14.2 on my OpenBSD system does not do this.






          share|improve this answer















          No, the * in .* means "any number of the preceding expression", i.e. zero or more of whatever character that matches the expression ..



          This means that .* will match aaaa as well as abcd since all of the characters in abcd matches .. It will also match an empty line, since it allows for zero matches.



          If you'd like to find a line that contains a repeated character, use



          /(.)11*/


          This expression matches "any character, then the same character, and then any number of more of the same character". The 1* could arguably be removed unless you're looking for lines that contain only a repeated character, in which case you should anchor the expression to the start and end of the line, as in



          /^(.)11*$/


          The ed editor supports basic regular expressions. The + modifier is an extended regular expression modifier. The ? that you get from ed when using /.+/ would be followed by no match (or No match in GNU ed) if you had enabled error explanations with the H command. This is because it tries to find a line with a + in it, preceded by some other character.



          The .+ extended regular expression ("match one or more of any character") is equivalent to the basic regular expression ..*, i.e. "match a character, and then zero or more of any character".



          According to its manual, GNU ed should support + in regular expressions, so that ..* is equivalent to .+, but GNU ed 1.14.2 on my OpenBSD system does not do this.







          share|improve this answer















          share|improve this answer



          share|improve this answer








          edited yesterday


























          answered yesterday









          Kusalananda

          100k13199311




          100k13199311







          • 1




            Even if the * referred to copies of the same character, it matches zero or more, so it would still match on any line since a zero amount of something is really easy to find...
            – ilkkachu
            yesterday






          • 1




            Great work and congrats on the 100K!
            – Stephen Rauch
            yesterday












          • 1




            Even if the * referred to copies of the same character, it matches zero or more, so it would still match on any line since a zero amount of something is really easy to find...
            – ilkkachu
            yesterday






          • 1




            Great work and congrats on the 100K!
            – Stephen Rauch
            yesterday







          1




          1




          Even if the * referred to copies of the same character, it matches zero or more, so it would still match on any line since a zero amount of something is really easy to find...
          – ilkkachu
          yesterday




          Even if the * referred to copies of the same character, it matches zero or more, so it would still match on any line since a zero amount of something is really easy to find...
          – ilkkachu
          yesterday




          1




          1




          Great work and congrats on the 100K!
          – Stephen Rauch
          yesterday




          Great work and congrats on the 100K!
          – Stephen Rauch
          yesterday












           

          draft saved


          draft discarded


























           


          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f460619%2fproblem-understaning%23new-answer', 'question_page');

          );

          Post as a guest













































































          Popular posts from this blog

          Peggy Mitchell

          Palaiologos

          The Forum (Inglewood, California)