Refine String using Python/Regular ExpressionHow to merge two dictionaries in a single expression?Calling an external command in PythonWhat are metaclasses in Python?How to validate an email address using a regular expression?How to get a function name as a string in Python?Regular expression to match a line that doesn't contain a wordHow do I make the first letter of a string uppercase in JavaScript?How to replace all occurrences of a string in JavaScriptDoes Python have a string 'contains' substring method?Remove all whitespace in a string in Python

Tub Drain SLOWLY Drains - If You Hold "Knob" Down It Drains At Regular Speed

Was Mohammed the most popular first name for boys born in Berlin in 2018?

Why is there a cap on 401k contributions?

Rusty Chain and back cassette – Replace or Repair?

Best species to breed to intelligence

Is it safe to keep the GPU on 100% utilization for a very long time?

Ugin's Conjurant vs. un-preventable damage

Are double contractions formal? Eg: "couldn't've" for "could not have"

Double underlining a result in a system of equations with calculation steps on the right side

Is there an idiom that means "revealing a secret unintentionally"?

Can you turn a recording upside-down?

Has there been evidence of any other gods?

Renting a house to a graduate student in my department

Employee is self-centered and affects the team negatively

Has everyone forgotten about wildfire?

How can Sam Wilson fulfill his future role?

Names of the Six Tastes

how to find out if there's files in a folder and exit accordingly (in KSH)

Program for finding longest run of zeros from a list of 100 random integers which are either 0 or 1

How to handle DM constantly stealing everything from sleeping characters?

TeX Gyre Pagella Math Integral sign much too small

How long can fsck take on a 30 TB volume?

Was there a contingency plan in place if Little Boy failed to detonate?

How can it be that ssh somename works, while nslookup somename does not?



Refine String using Python/Regular Expression


How to merge two dictionaries in a single expression?Calling an external command in PythonWhat are metaclasses in Python?How to validate an email address using a regular expression?How to get a function name as a string in Python?Regular expression to match a line that doesn't contain a wordHow do I make the first letter of a string uppercase in JavaScript?How to replace all occurrences of a string in JavaScriptDoes Python have a string 'contains' substring method?Remove all whitespace in a string in Python






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








-1















please help me with refining this string using python/regex.
It also have large whitespaces.



/**
* this is comment this is comment
* this is comment
* <blank line>
* this is comment
* this is comment
* <blank line>
* this is comment
*/


how to get a plain text by removing /**, *



I expect the output string should be :



this is comment

this is comment

this is comment

this is comment

this is comment










share|improve this question




























    -1















    please help me with refining this string using python/regex.
    It also have large whitespaces.



    /**
    * this is comment this is comment
    * this is comment
    * <blank line>
    * this is comment
    * this is comment
    * <blank line>
    * this is comment
    */


    how to get a plain text by removing /**, *



    I expect the output string should be :



    this is comment

    this is comment

    this is comment

    this is comment

    this is comment










    share|improve this question
























      -1












      -1








      -1








      please help me with refining this string using python/regex.
      It also have large whitespaces.



      /**
      * this is comment this is comment
      * this is comment
      * <blank line>
      * this is comment
      * this is comment
      * <blank line>
      * this is comment
      */


      how to get a plain text by removing /**, *



      I expect the output string should be :



      this is comment

      this is comment

      this is comment

      this is comment

      this is comment










      share|improve this question














      please help me with refining this string using python/regex.
      It also have large whitespaces.



      /**
      * this is comment this is comment
      * this is comment
      * <blank line>
      * this is comment
      * this is comment
      * <blank line>
      * this is comment
      */


      how to get a plain text by removing /**, *



      I expect the output string should be :



      this is comment

      this is comment

      this is comment

      this is comment

      this is comment







      python regex python-3.x regular-language






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Mar 23 at 8:58









      Shahu RongheShahu Ronghe

      426




      426






















          2 Answers
          2






          active

          oldest

          votes


















          1














          You can use the sub() function from the RegEx module to match unwanted characters and format the input string. Here's a proof of concept which gives the output you want. You can test it here: https://repl.it/@glhr/regex-fun



          import re

          inputStr = """/**
          * this is comment this is comment
          * this is comment
          *
          * this is comment
          * this is comment
          *
          * this is comment
          */"""

          formattedStr = re.sub("[*/]", "", inputStr) # comments
          formattedStr = re.sub("ns2,|s2,", "n", formattedStr) # extra whitespaces
          formattedStr = re.sub("^n+|n+$|n2,", "", formattedStr) # extra blank lines
          print(formattedStr)


          You can experiment with regular expressions on sites like https://regexr.com/






          share|improve this answer
































            2














            As it is clear now that OP expected that comment this is comment six times, hence I suggest using this regex,



            ^[ /*]+n?| 2,(.*(n))


            And replace it with 21.



            Demo



            Also, you really don't need three separate regex (as other accepted answer) to achieve this, instead it can be done using just a single regex.



            Here is a Python code demo,



            import re

            s = '''/**
            * this is comment this is comment
            * this is comment
            *
            * this is comment
            * this is comment
            *
            * this is comment
            */'''

            print(re.sub(r'(?m)^[ /*]+n?| 2,(.*(n))', r'21', s))


            Prints following and notice I have enabled multiline mode using (?m) before the regex as suggested by FailSafe and many thanks to him for suggesting it as it wasn't otherwise noticeable,



            this is comment
            this is comment
            this is comment
            this is comment
            this is comment
            this is comment


            Let me know if you need explanation of any part in my answer.






            share|improve this answer




















            • 1





              @FailSafe: Yes agree. Actually OP's post is a little incorrect. In his post his expected output lists this is comment five times where as he actually expected it six times as can be seen in expected answer, which is why I think he didn't accept my answer but that's not my fault :). Also when I posted this answer I was in a little hurry else I always give a demo code solution too. The other answer uses three different substitution otherwise it can be done in a single substitution with this regex. Check Demo

              – Pushpesh Kumar Rajwanshi
              Mar 23 at 17:00






            • 1





              @"Pushpesh Kumar Rajwanshi" Yes definitely. I saw the mistake and wondered if he wanted it broken out, but that was negligible. Still, I'm +1'ing yours, but just want to ask you to edit it s it mentioned that multiline needs to be enabled.

              – FailSafe
              Mar 23 at 17:07






            • 1





              @FailSafe: Thanks for upvote :) I appreciate you giving time to read my answer. I've updated my answer with a regex that gives correct output of listing comment six times and also gave python code solution, enabling multiline mode too and mentioning it specifically as you suggested and you were right indeed. People generally tend to miss such small attributes.

              – Pushpesh Kumar Rajwanshi
              Mar 23 at 17:12






            • 1





              @"Pushpesh Kumar Rajwanshi" Holy crap. Re.Sub substitutes on the fly!! I spent like the last half hour trying to figure out how you got * this is comment this is comment to print on separate lines. Wow. I learned something new.

              – FailSafe
              Mar 23 at 17:48







            • 1





              @FailSafe: Yes it does and my solution exploits that well to get the desired results and hence is a little non-trivial.

              – Pushpesh Kumar Rajwanshi
              Mar 23 at 19:26











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



            );













            draft saved

            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55312155%2frefine-string-using-python-regular-expression%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














            You can use the sub() function from the RegEx module to match unwanted characters and format the input string. Here's a proof of concept which gives the output you want. You can test it here: https://repl.it/@glhr/regex-fun



            import re

            inputStr = """/**
            * this is comment this is comment
            * this is comment
            *
            * this is comment
            * this is comment
            *
            * this is comment
            */"""

            formattedStr = re.sub("[*/]", "", inputStr) # comments
            formattedStr = re.sub("ns2,|s2,", "n", formattedStr) # extra whitespaces
            formattedStr = re.sub("^n+|n+$|n2,", "", formattedStr) # extra blank lines
            print(formattedStr)


            You can experiment with regular expressions on sites like https://regexr.com/






            share|improve this answer





























              1














              You can use the sub() function from the RegEx module to match unwanted characters and format the input string. Here's a proof of concept which gives the output you want. You can test it here: https://repl.it/@glhr/regex-fun



              import re

              inputStr = """/**
              * this is comment this is comment
              * this is comment
              *
              * this is comment
              * this is comment
              *
              * this is comment
              */"""

              formattedStr = re.sub("[*/]", "", inputStr) # comments
              formattedStr = re.sub("ns2,|s2,", "n", formattedStr) # extra whitespaces
              formattedStr = re.sub("^n+|n+$|n2,", "", formattedStr) # extra blank lines
              print(formattedStr)


              You can experiment with regular expressions on sites like https://regexr.com/






              share|improve this answer



























                1












                1








                1







                You can use the sub() function from the RegEx module to match unwanted characters and format the input string. Here's a proof of concept which gives the output you want. You can test it here: https://repl.it/@glhr/regex-fun



                import re

                inputStr = """/**
                * this is comment this is comment
                * this is comment
                *
                * this is comment
                * this is comment
                *
                * this is comment
                */"""

                formattedStr = re.sub("[*/]", "", inputStr) # comments
                formattedStr = re.sub("ns2,|s2,", "n", formattedStr) # extra whitespaces
                formattedStr = re.sub("^n+|n+$|n2,", "", formattedStr) # extra blank lines
                print(formattedStr)


                You can experiment with regular expressions on sites like https://regexr.com/






                share|improve this answer















                You can use the sub() function from the RegEx module to match unwanted characters and format the input string. Here's a proof of concept which gives the output you want. You can test it here: https://repl.it/@glhr/regex-fun



                import re

                inputStr = """/**
                * this is comment this is comment
                * this is comment
                *
                * this is comment
                * this is comment
                *
                * this is comment
                */"""

                formattedStr = re.sub("[*/]", "", inputStr) # comments
                formattedStr = re.sub("ns2,|s2,", "n", formattedStr) # extra whitespaces
                formattedStr = re.sub("^n+|n+$|n2,", "", formattedStr) # extra blank lines
                print(formattedStr)


                You can experiment with regular expressions on sites like https://regexr.com/







                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Mar 23 at 10:06

























                answered Mar 23 at 9:48









                glhrglhr

                3,2421921




                3,2421921























                    2














                    As it is clear now that OP expected that comment this is comment six times, hence I suggest using this regex,



                    ^[ /*]+n?| 2,(.*(n))


                    And replace it with 21.



                    Demo



                    Also, you really don't need three separate regex (as other accepted answer) to achieve this, instead it can be done using just a single regex.



                    Here is a Python code demo,



                    import re

                    s = '''/**
                    * this is comment this is comment
                    * this is comment
                    *
                    * this is comment
                    * this is comment
                    *
                    * this is comment
                    */'''

                    print(re.sub(r'(?m)^[ /*]+n?| 2,(.*(n))', r'21', s))


                    Prints following and notice I have enabled multiline mode using (?m) before the regex as suggested by FailSafe and many thanks to him for suggesting it as it wasn't otherwise noticeable,



                    this is comment
                    this is comment
                    this is comment
                    this is comment
                    this is comment
                    this is comment


                    Let me know if you need explanation of any part in my answer.






                    share|improve this answer




















                    • 1





                      @FailSafe: Yes agree. Actually OP's post is a little incorrect. In his post his expected output lists this is comment five times where as he actually expected it six times as can be seen in expected answer, which is why I think he didn't accept my answer but that's not my fault :). Also when I posted this answer I was in a little hurry else I always give a demo code solution too. The other answer uses three different substitution otherwise it can be done in a single substitution with this regex. Check Demo

                      – Pushpesh Kumar Rajwanshi
                      Mar 23 at 17:00






                    • 1





                      @"Pushpesh Kumar Rajwanshi" Yes definitely. I saw the mistake and wondered if he wanted it broken out, but that was negligible. Still, I'm +1'ing yours, but just want to ask you to edit it s it mentioned that multiline needs to be enabled.

                      – FailSafe
                      Mar 23 at 17:07






                    • 1





                      @FailSafe: Thanks for upvote :) I appreciate you giving time to read my answer. I've updated my answer with a regex that gives correct output of listing comment six times and also gave python code solution, enabling multiline mode too and mentioning it specifically as you suggested and you were right indeed. People generally tend to miss such small attributes.

                      – Pushpesh Kumar Rajwanshi
                      Mar 23 at 17:12






                    • 1





                      @"Pushpesh Kumar Rajwanshi" Holy crap. Re.Sub substitutes on the fly!! I spent like the last half hour trying to figure out how you got * this is comment this is comment to print on separate lines. Wow. I learned something new.

                      – FailSafe
                      Mar 23 at 17:48







                    • 1





                      @FailSafe: Yes it does and my solution exploits that well to get the desired results and hence is a little non-trivial.

                      – Pushpesh Kumar Rajwanshi
                      Mar 23 at 19:26















                    2














                    As it is clear now that OP expected that comment this is comment six times, hence I suggest using this regex,



                    ^[ /*]+n?| 2,(.*(n))


                    And replace it with 21.



                    Demo



                    Also, you really don't need three separate regex (as other accepted answer) to achieve this, instead it can be done using just a single regex.



                    Here is a Python code demo,



                    import re

                    s = '''/**
                    * this is comment this is comment
                    * this is comment
                    *
                    * this is comment
                    * this is comment
                    *
                    * this is comment
                    */'''

                    print(re.sub(r'(?m)^[ /*]+n?| 2,(.*(n))', r'21', s))


                    Prints following and notice I have enabled multiline mode using (?m) before the regex as suggested by FailSafe and many thanks to him for suggesting it as it wasn't otherwise noticeable,



                    this is comment
                    this is comment
                    this is comment
                    this is comment
                    this is comment
                    this is comment


                    Let me know if you need explanation of any part in my answer.






                    share|improve this answer




















                    • 1





                      @FailSafe: Yes agree. Actually OP's post is a little incorrect. In his post his expected output lists this is comment five times where as he actually expected it six times as can be seen in expected answer, which is why I think he didn't accept my answer but that's not my fault :). Also when I posted this answer I was in a little hurry else I always give a demo code solution too. The other answer uses three different substitution otherwise it can be done in a single substitution with this regex. Check Demo

                      – Pushpesh Kumar Rajwanshi
                      Mar 23 at 17:00






                    • 1





                      @"Pushpesh Kumar Rajwanshi" Yes definitely. I saw the mistake and wondered if he wanted it broken out, but that was negligible. Still, I'm +1'ing yours, but just want to ask you to edit it s it mentioned that multiline needs to be enabled.

                      – FailSafe
                      Mar 23 at 17:07






                    • 1





                      @FailSafe: Thanks for upvote :) I appreciate you giving time to read my answer. I've updated my answer with a regex that gives correct output of listing comment six times and also gave python code solution, enabling multiline mode too and mentioning it specifically as you suggested and you were right indeed. People generally tend to miss such small attributes.

                      – Pushpesh Kumar Rajwanshi
                      Mar 23 at 17:12






                    • 1





                      @"Pushpesh Kumar Rajwanshi" Holy crap. Re.Sub substitutes on the fly!! I spent like the last half hour trying to figure out how you got * this is comment this is comment to print on separate lines. Wow. I learned something new.

                      – FailSafe
                      Mar 23 at 17:48







                    • 1





                      @FailSafe: Yes it does and my solution exploits that well to get the desired results and hence is a little non-trivial.

                      – Pushpesh Kumar Rajwanshi
                      Mar 23 at 19:26













                    2












                    2








                    2







                    As it is clear now that OP expected that comment this is comment six times, hence I suggest using this regex,



                    ^[ /*]+n?| 2,(.*(n))


                    And replace it with 21.



                    Demo



                    Also, you really don't need three separate regex (as other accepted answer) to achieve this, instead it can be done using just a single regex.



                    Here is a Python code demo,



                    import re

                    s = '''/**
                    * this is comment this is comment
                    * this is comment
                    *
                    * this is comment
                    * this is comment
                    *
                    * this is comment
                    */'''

                    print(re.sub(r'(?m)^[ /*]+n?| 2,(.*(n))', r'21', s))


                    Prints following and notice I have enabled multiline mode using (?m) before the regex as suggested by FailSafe and many thanks to him for suggesting it as it wasn't otherwise noticeable,



                    this is comment
                    this is comment
                    this is comment
                    this is comment
                    this is comment
                    this is comment


                    Let me know if you need explanation of any part in my answer.






                    share|improve this answer















                    As it is clear now that OP expected that comment this is comment six times, hence I suggest using this regex,



                    ^[ /*]+n?| 2,(.*(n))


                    And replace it with 21.



                    Demo



                    Also, you really don't need three separate regex (as other accepted answer) to achieve this, instead it can be done using just a single regex.



                    Here is a Python code demo,



                    import re

                    s = '''/**
                    * this is comment this is comment
                    * this is comment
                    *
                    * this is comment
                    * this is comment
                    *
                    * this is comment
                    */'''

                    print(re.sub(r'(?m)^[ /*]+n?| 2,(.*(n))', r'21', s))


                    Prints following and notice I have enabled multiline mode using (?m) before the regex as suggested by FailSafe and many thanks to him for suggesting it as it wasn't otherwise noticeable,



                    this is comment
                    this is comment
                    this is comment
                    this is comment
                    this is comment
                    this is comment


                    Let me know if you need explanation of any part in my answer.







                    share|improve this answer














                    share|improve this answer



                    share|improve this answer








                    edited Mar 23 at 17:07

























                    answered Mar 23 at 9:42









                    Pushpesh Kumar RajwanshiPushpesh Kumar Rajwanshi

                    15.6k21332




                    15.6k21332







                    • 1





                      @FailSafe: Yes agree. Actually OP's post is a little incorrect. In his post his expected output lists this is comment five times where as he actually expected it six times as can be seen in expected answer, which is why I think he didn't accept my answer but that's not my fault :). Also when I posted this answer I was in a little hurry else I always give a demo code solution too. The other answer uses three different substitution otherwise it can be done in a single substitution with this regex. Check Demo

                      – Pushpesh Kumar Rajwanshi
                      Mar 23 at 17:00






                    • 1





                      @"Pushpesh Kumar Rajwanshi" Yes definitely. I saw the mistake and wondered if he wanted it broken out, but that was negligible. Still, I'm +1'ing yours, but just want to ask you to edit it s it mentioned that multiline needs to be enabled.

                      – FailSafe
                      Mar 23 at 17:07






                    • 1





                      @FailSafe: Thanks for upvote :) I appreciate you giving time to read my answer. I've updated my answer with a regex that gives correct output of listing comment six times and also gave python code solution, enabling multiline mode too and mentioning it specifically as you suggested and you were right indeed. People generally tend to miss such small attributes.

                      – Pushpesh Kumar Rajwanshi
                      Mar 23 at 17:12






                    • 1





                      @"Pushpesh Kumar Rajwanshi" Holy crap. Re.Sub substitutes on the fly!! I spent like the last half hour trying to figure out how you got * this is comment this is comment to print on separate lines. Wow. I learned something new.

                      – FailSafe
                      Mar 23 at 17:48







                    • 1





                      @FailSafe: Yes it does and my solution exploits that well to get the desired results and hence is a little non-trivial.

                      – Pushpesh Kumar Rajwanshi
                      Mar 23 at 19:26












                    • 1





                      @FailSafe: Yes agree. Actually OP's post is a little incorrect. In his post his expected output lists this is comment five times where as he actually expected it six times as can be seen in expected answer, which is why I think he didn't accept my answer but that's not my fault :). Also when I posted this answer I was in a little hurry else I always give a demo code solution too. The other answer uses three different substitution otherwise it can be done in a single substitution with this regex. Check Demo

                      – Pushpesh Kumar Rajwanshi
                      Mar 23 at 17:00






                    • 1





                      @"Pushpesh Kumar Rajwanshi" Yes definitely. I saw the mistake and wondered if he wanted it broken out, but that was negligible. Still, I'm +1'ing yours, but just want to ask you to edit it s it mentioned that multiline needs to be enabled.

                      – FailSafe
                      Mar 23 at 17:07






                    • 1





                      @FailSafe: Thanks for upvote :) I appreciate you giving time to read my answer. I've updated my answer with a regex that gives correct output of listing comment six times and also gave python code solution, enabling multiline mode too and mentioning it specifically as you suggested and you were right indeed. People generally tend to miss such small attributes.

                      – Pushpesh Kumar Rajwanshi
                      Mar 23 at 17:12






                    • 1





                      @"Pushpesh Kumar Rajwanshi" Holy crap. Re.Sub substitutes on the fly!! I spent like the last half hour trying to figure out how you got * this is comment this is comment to print on separate lines. Wow. I learned something new.

                      – FailSafe
                      Mar 23 at 17:48







                    • 1





                      @FailSafe: Yes it does and my solution exploits that well to get the desired results and hence is a little non-trivial.

                      – Pushpesh Kumar Rajwanshi
                      Mar 23 at 19:26







                    1




                    1





                    @FailSafe: Yes agree. Actually OP's post is a little incorrect. In his post his expected output lists this is comment five times where as he actually expected it six times as can be seen in expected answer, which is why I think he didn't accept my answer but that's not my fault :). Also when I posted this answer I was in a little hurry else I always give a demo code solution too. The other answer uses three different substitution otherwise it can be done in a single substitution with this regex. Check Demo

                    – Pushpesh Kumar Rajwanshi
                    Mar 23 at 17:00





                    @FailSafe: Yes agree. Actually OP's post is a little incorrect. In his post his expected output lists this is comment five times where as he actually expected it six times as can be seen in expected answer, which is why I think he didn't accept my answer but that's not my fault :). Also when I posted this answer I was in a little hurry else I always give a demo code solution too. The other answer uses three different substitution otherwise it can be done in a single substitution with this regex. Check Demo

                    – Pushpesh Kumar Rajwanshi
                    Mar 23 at 17:00




                    1




                    1





                    @"Pushpesh Kumar Rajwanshi" Yes definitely. I saw the mistake and wondered if he wanted it broken out, but that was negligible. Still, I'm +1'ing yours, but just want to ask you to edit it s it mentioned that multiline needs to be enabled.

                    – FailSafe
                    Mar 23 at 17:07





                    @"Pushpesh Kumar Rajwanshi" Yes definitely. I saw the mistake and wondered if he wanted it broken out, but that was negligible. Still, I'm +1'ing yours, but just want to ask you to edit it s it mentioned that multiline needs to be enabled.

                    – FailSafe
                    Mar 23 at 17:07




                    1




                    1





                    @FailSafe: Thanks for upvote :) I appreciate you giving time to read my answer. I've updated my answer with a regex that gives correct output of listing comment six times and also gave python code solution, enabling multiline mode too and mentioning it specifically as you suggested and you were right indeed. People generally tend to miss such small attributes.

                    – Pushpesh Kumar Rajwanshi
                    Mar 23 at 17:12





                    @FailSafe: Thanks for upvote :) I appreciate you giving time to read my answer. I've updated my answer with a regex that gives correct output of listing comment six times and also gave python code solution, enabling multiline mode too and mentioning it specifically as you suggested and you were right indeed. People generally tend to miss such small attributes.

                    – Pushpesh Kumar Rajwanshi
                    Mar 23 at 17:12




                    1




                    1





                    @"Pushpesh Kumar Rajwanshi" Holy crap. Re.Sub substitutes on the fly!! I spent like the last half hour trying to figure out how you got * this is comment this is comment to print on separate lines. Wow. I learned something new.

                    – FailSafe
                    Mar 23 at 17:48






                    @"Pushpesh Kumar Rajwanshi" Holy crap. Re.Sub substitutes on the fly!! I spent like the last half hour trying to figure out how you got * this is comment this is comment to print on separate lines. Wow. I learned something new.

                    – FailSafe
                    Mar 23 at 17:48





                    1




                    1





                    @FailSafe: Yes it does and my solution exploits that well to get the desired results and hence is a little non-trivial.

                    – Pushpesh Kumar Rajwanshi
                    Mar 23 at 19:26





                    @FailSafe: Yes it does and my solution exploits that well to get the desired results and hence is a little non-trivial.

                    – Pushpesh Kumar Rajwanshi
                    Mar 23 at 19:26

















                    draft saved

                    draft discarded
















































                    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.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55312155%2frefine-string-using-python-regular-expression%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

                    Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

                    Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

                    Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript