What are some PRACTICAL scenarios for using the regex + symbol?

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











up vote
0
down vote

favorite












So, I think I know what the RegEx + symbol does (looks for the preceding character 1 or more times). I think I get how to use it...



echo "This is a good sentence." | awk '/go+d/ print $0'


(finds good, gooood, gooooooood)



But, I'm having trouble coming up with a practical, objective reason for wanting to look for this kind of repetition. I need scenarios to give its purpose some context for explanation to others.



Thanks for helping and letting me lean on your knowledge and experiences.










share|improve this question





















  • It makes more sense with digits, as I see it...
    – jasonwryan
    Oct 10 '17 at 2:14










  • I thought that too, but I couldn't think of a scenario to explain how that would look.
    – dlowrie290
    Oct 10 '17 at 2:22






  • 1




    What about when you want to slurp up whitespace? At least one space, for example. s+. Think about character classes rather than individual characters.
    – B Layer
    Oct 10 '17 at 2:28











  • That is EXACTLY the kind of thing I'm looking for. A great example of why you would use this type of functionality.
    – dlowrie290
    Oct 10 '17 at 2:33














up vote
0
down vote

favorite












So, I think I know what the RegEx + symbol does (looks for the preceding character 1 or more times). I think I get how to use it...



echo "This is a good sentence." | awk '/go+d/ print $0'


(finds good, gooood, gooooooood)



But, I'm having trouble coming up with a practical, objective reason for wanting to look for this kind of repetition. I need scenarios to give its purpose some context for explanation to others.



Thanks for helping and letting me lean on your knowledge and experiences.










share|improve this question





















  • It makes more sense with digits, as I see it...
    – jasonwryan
    Oct 10 '17 at 2:14










  • I thought that too, but I couldn't think of a scenario to explain how that would look.
    – dlowrie290
    Oct 10 '17 at 2:22






  • 1




    What about when you want to slurp up whitespace? At least one space, for example. s+. Think about character classes rather than individual characters.
    – B Layer
    Oct 10 '17 at 2:28











  • That is EXACTLY the kind of thing I'm looking for. A great example of why you would use this type of functionality.
    – dlowrie290
    Oct 10 '17 at 2:33












up vote
0
down vote

favorite









up vote
0
down vote

favorite











So, I think I know what the RegEx + symbol does (looks for the preceding character 1 or more times). I think I get how to use it...



echo "This is a good sentence." | awk '/go+d/ print $0'


(finds good, gooood, gooooooood)



But, I'm having trouble coming up with a practical, objective reason for wanting to look for this kind of repetition. I need scenarios to give its purpose some context for explanation to others.



Thanks for helping and letting me lean on your knowledge and experiences.










share|improve this question













So, I think I know what the RegEx + symbol does (looks for the preceding character 1 or more times). I think I get how to use it...



echo "This is a good sentence." | awk '/go+d/ print $0'


(finds good, gooood, gooooooood)



But, I'm having trouble coming up with a practical, objective reason for wanting to look for this kind of repetition. I need scenarios to give its purpose some context for explanation to others.



Thanks for helping and letting me lean on your knowledge and experiences.







regular-expression






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Oct 10 '17 at 2:09









dlowrie290

8410




8410











  • It makes more sense with digits, as I see it...
    – jasonwryan
    Oct 10 '17 at 2:14










  • I thought that too, but I couldn't think of a scenario to explain how that would look.
    – dlowrie290
    Oct 10 '17 at 2:22






  • 1




    What about when you want to slurp up whitespace? At least one space, for example. s+. Think about character classes rather than individual characters.
    – B Layer
    Oct 10 '17 at 2:28











  • That is EXACTLY the kind of thing I'm looking for. A great example of why you would use this type of functionality.
    – dlowrie290
    Oct 10 '17 at 2:33
















  • It makes more sense with digits, as I see it...
    – jasonwryan
    Oct 10 '17 at 2:14










  • I thought that too, but I couldn't think of a scenario to explain how that would look.
    – dlowrie290
    Oct 10 '17 at 2:22






  • 1




    What about when you want to slurp up whitespace? At least one space, for example. s+. Think about character classes rather than individual characters.
    – B Layer
    Oct 10 '17 at 2:28











  • That is EXACTLY the kind of thing I'm looking for. A great example of why you would use this type of functionality.
    – dlowrie290
    Oct 10 '17 at 2:33















It makes more sense with digits, as I see it...
– jasonwryan
Oct 10 '17 at 2:14




It makes more sense with digits, as I see it...
– jasonwryan
Oct 10 '17 at 2:14












I thought that too, but I couldn't think of a scenario to explain how that would look.
– dlowrie290
Oct 10 '17 at 2:22




I thought that too, but I couldn't think of a scenario to explain how that would look.
– dlowrie290
Oct 10 '17 at 2:22




1




1




What about when you want to slurp up whitespace? At least one space, for example. s+. Think about character classes rather than individual characters.
– B Layer
Oct 10 '17 at 2:28





What about when you want to slurp up whitespace? At least one space, for example. s+. Think about character classes rather than individual characters.
– B Layer
Oct 10 '17 at 2:28













That is EXACTLY the kind of thing I'm looking for. A great example of why you would use this type of functionality.
– dlowrie290
Oct 10 '17 at 2:33




That is EXACTLY the kind of thing I'm looking for. A great example of why you would use this type of functionality.
– dlowrie290
Oct 10 '17 at 2:33










2 Answers
2






active

oldest

votes

















up vote
4
down vote



accepted










You're thinking about individual characters when you'll find that + is much more useful with character classes...



  • Whitespace: s+

  • Non-numerical characters: [^0-9]+

  • A word: w+

  • Non-empty string: .+

  • Etc.

Practical examples should be fairly easy to think of with these. Perhaps I want to find only lines that have indented text: ^s+S. Or I might want to find all non-empty lines: ^.+$. I can come up with more if you need them. ;)






share|improve this answer






















  • No, [0-9] is numerical. [^0-9] is NOT numerical.
    – B Layer
    Oct 10 '17 at 2:44










  • My bad, I read it as ^[...
    – jasonwryan
    Oct 10 '17 at 2:45










  • No worries. I suspected that that's what you saw. :)
    – B Layer
    Oct 10 '17 at 2:45

















up vote
3
down vote













Here's a real-world instance of damage caused by using * instead of + (mostly because OP didn't realise that they would end up using regexes instead of wildcards): Why did this command delete every package?




Arguments to apt-get install and apt-get remove are extended
regular expressions, not shell
wildcards;
wine* means win followed by any number of e, and since this can
match any part of the package name, this means any package whose name
contains win as a substring.




OP had run sudo apt-get remove wine*, ended up removing the majority of the installed packages in their system. wine+, on the other hand, would have removed packages with wine in it.






share|improve this answer




















    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%2f397155%2fwhat-are-some-practical-scenarios-for-using-the-regex-symbol%23new-answer', 'question_page');

    );

    Post as a guest






























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    4
    down vote



    accepted










    You're thinking about individual characters when you'll find that + is much more useful with character classes...



    • Whitespace: s+

    • Non-numerical characters: [^0-9]+

    • A word: w+

    • Non-empty string: .+

    • Etc.

    Practical examples should be fairly easy to think of with these. Perhaps I want to find only lines that have indented text: ^s+S. Or I might want to find all non-empty lines: ^.+$. I can come up with more if you need them. ;)






    share|improve this answer






















    • No, [0-9] is numerical. [^0-9] is NOT numerical.
      – B Layer
      Oct 10 '17 at 2:44










    • My bad, I read it as ^[...
      – jasonwryan
      Oct 10 '17 at 2:45










    • No worries. I suspected that that's what you saw. :)
      – B Layer
      Oct 10 '17 at 2:45














    up vote
    4
    down vote



    accepted










    You're thinking about individual characters when you'll find that + is much more useful with character classes...



    • Whitespace: s+

    • Non-numerical characters: [^0-9]+

    • A word: w+

    • Non-empty string: .+

    • Etc.

    Practical examples should be fairly easy to think of with these. Perhaps I want to find only lines that have indented text: ^s+S. Or I might want to find all non-empty lines: ^.+$. I can come up with more if you need them. ;)






    share|improve this answer






















    • No, [0-9] is numerical. [^0-9] is NOT numerical.
      – B Layer
      Oct 10 '17 at 2:44










    • My bad, I read it as ^[...
      – jasonwryan
      Oct 10 '17 at 2:45










    • No worries. I suspected that that's what you saw. :)
      – B Layer
      Oct 10 '17 at 2:45












    up vote
    4
    down vote



    accepted







    up vote
    4
    down vote



    accepted






    You're thinking about individual characters when you'll find that + is much more useful with character classes...



    • Whitespace: s+

    • Non-numerical characters: [^0-9]+

    • A word: w+

    • Non-empty string: .+

    • Etc.

    Practical examples should be fairly easy to think of with these. Perhaps I want to find only lines that have indented text: ^s+S. Or I might want to find all non-empty lines: ^.+$. I can come up with more if you need them. ;)






    share|improve this answer














    You're thinking about individual characters when you'll find that + is much more useful with character classes...



    • Whitespace: s+

    • Non-numerical characters: [^0-9]+

    • A word: w+

    • Non-empty string: .+

    • Etc.

    Practical examples should be fairly easy to think of with these. Perhaps I want to find only lines that have indented text: ^s+S. Or I might want to find all non-empty lines: ^.+$. I can come up with more if you need them. ;)







    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Oct 10 '17 at 3:29

























    answered Oct 10 '17 at 2:42









    B Layer

    3,9241525




    3,9241525











    • No, [0-9] is numerical. [^0-9] is NOT numerical.
      – B Layer
      Oct 10 '17 at 2:44










    • My bad, I read it as ^[...
      – jasonwryan
      Oct 10 '17 at 2:45










    • No worries. I suspected that that's what you saw. :)
      – B Layer
      Oct 10 '17 at 2:45
















    • No, [0-9] is numerical. [^0-9] is NOT numerical.
      – B Layer
      Oct 10 '17 at 2:44










    • My bad, I read it as ^[...
      – jasonwryan
      Oct 10 '17 at 2:45










    • No worries. I suspected that that's what you saw. :)
      – B Layer
      Oct 10 '17 at 2:45















    No, [0-9] is numerical. [^0-9] is NOT numerical.
    – B Layer
    Oct 10 '17 at 2:44




    No, [0-9] is numerical. [^0-9] is NOT numerical.
    – B Layer
    Oct 10 '17 at 2:44












    My bad, I read it as ^[...
    – jasonwryan
    Oct 10 '17 at 2:45




    My bad, I read it as ^[...
    – jasonwryan
    Oct 10 '17 at 2:45












    No worries. I suspected that that's what you saw. :)
    – B Layer
    Oct 10 '17 at 2:45




    No worries. I suspected that that's what you saw. :)
    – B Layer
    Oct 10 '17 at 2:45












    up vote
    3
    down vote













    Here's a real-world instance of damage caused by using * instead of + (mostly because OP didn't realise that they would end up using regexes instead of wildcards): Why did this command delete every package?




    Arguments to apt-get install and apt-get remove are extended
    regular expressions, not shell
    wildcards;
    wine* means win followed by any number of e, and since this can
    match any part of the package name, this means any package whose name
    contains win as a substring.




    OP had run sudo apt-get remove wine*, ended up removing the majority of the installed packages in their system. wine+, on the other hand, would have removed packages with wine in it.






    share|improve this answer
























      up vote
      3
      down vote













      Here's a real-world instance of damage caused by using * instead of + (mostly because OP didn't realise that they would end up using regexes instead of wildcards): Why did this command delete every package?




      Arguments to apt-get install and apt-get remove are extended
      regular expressions, not shell
      wildcards;
      wine* means win followed by any number of e, and since this can
      match any part of the package name, this means any package whose name
      contains win as a substring.




      OP had run sudo apt-get remove wine*, ended up removing the majority of the installed packages in their system. wine+, on the other hand, would have removed packages with wine in it.






      share|improve this answer






















        up vote
        3
        down vote










        up vote
        3
        down vote









        Here's a real-world instance of damage caused by using * instead of + (mostly because OP didn't realise that they would end up using regexes instead of wildcards): Why did this command delete every package?




        Arguments to apt-get install and apt-get remove are extended
        regular expressions, not shell
        wildcards;
        wine* means win followed by any number of e, and since this can
        match any part of the package name, this means any package whose name
        contains win as a substring.




        OP had run sudo apt-get remove wine*, ended up removing the majority of the installed packages in their system. wine+, on the other hand, would have removed packages with wine in it.






        share|improve this answer












        Here's a real-world instance of damage caused by using * instead of + (mostly because OP didn't realise that they would end up using regexes instead of wildcards): Why did this command delete every package?




        Arguments to apt-get install and apt-get remove are extended
        regular expressions, not shell
        wildcards;
        wine* means win followed by any number of e, and since this can
        match any part of the package name, this means any package whose name
        contains win as a substring.




        OP had run sudo apt-get remove wine*, ended up removing the majority of the installed packages in their system. wine+, on the other hand, would have removed packages with wine in it.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Oct 10 '17 at 2:44









        muru

        33.6k577144




        33.6k577144



























             

            draft saved


            draft discarded















































             


            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f397155%2fwhat-are-some-practical-scenarios-for-using-the-regex-symbol%23new-answer', 'question_page');

            );

            Post as a guest













































































            Popular posts from this blog

            How to check contact read email or not when send email to Individual?

            Displaying single band from multi-band raster using QGIS

            How many registers does an x86_64 CPU actually have?