Quite confused about `?` in vim's regex [duplicate]












1
















This question already has an answer here:




  • How can I make my match non greedy in vim?

    8 answers




I'we been trying to do simple substitution in vim, and find out that the ? in vim not works with * or +, saying that (NFA regexp) Can't have a multi follow a multi, in the vim:



i want it to stop here, not here
~
~
~
[NORMAL] ...
:%s/^(.*?)here//


If I remove ? it works, but the it regex matches up to 2nd here.



But with normal regex it works: https://regex101.com/r/iHdxxl/1



Why it isn't possible to use ? with * or + in vim?










share|improve this question















marked as duplicate by mercator, Community Jan 19 at 11:39


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.























    1
















    This question already has an answer here:




    • How can I make my match non greedy in vim?

      8 answers




    I'we been trying to do simple substitution in vim, and find out that the ? in vim not works with * or +, saying that (NFA regexp) Can't have a multi follow a multi, in the vim:



    i want it to stop here, not here
    ~
    ~
    ~
    [NORMAL] ...
    :%s/^(.*?)here//


    If I remove ? it works, but the it regex matches up to 2nd here.



    But with normal regex it works: https://regex101.com/r/iHdxxl/1



    Why it isn't possible to use ? with * or + in vim?










    share|improve this question















    marked as duplicate by mercator, Community Jan 19 at 11:39


    This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.





















      1












      1








      1









      This question already has an answer here:




      • How can I make my match non greedy in vim?

        8 answers




      I'we been trying to do simple substitution in vim, and find out that the ? in vim not works with * or +, saying that (NFA regexp) Can't have a multi follow a multi, in the vim:



      i want it to stop here, not here
      ~
      ~
      ~
      [NORMAL] ...
      :%s/^(.*?)here//


      If I remove ? it works, but the it regex matches up to 2nd here.



      But with normal regex it works: https://regex101.com/r/iHdxxl/1



      Why it isn't possible to use ? with * or + in vim?










      share|improve this question

















      This question already has an answer here:




      • How can I make my match non greedy in vim?

        8 answers




      I'we been trying to do simple substitution in vim, and find out that the ? in vim not works with * or +, saying that (NFA regexp) Can't have a multi follow a multi, in the vim:



      i want it to stop here, not here
      ~
      ~
      ~
      [NORMAL] ...
      :%s/^(.*?)here//


      If I remove ? it works, but the it regex matches up to 2nd here.



      But with normal regex it works: https://regex101.com/r/iHdxxl/1



      Why it isn't possible to use ? with * or + in vim?





      This question already has an answer here:




      • How can I make my match non greedy in vim?

        8 answers








      regex vim






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Jan 19 at 9:36







      BladeMight

















      asked Jan 19 at 9:25









      BladeMightBladeMight

      1,4351225




      1,4351225




      marked as duplicate by mercator, Community Jan 19 at 11:39


      This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.









      marked as duplicate by mercator, Community Jan 19 at 11:39


      This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.


























          2 Answers
          2






          active

          oldest

          votes


















          3














          As stated there, you can't add the ? char in vim after the asterix.
          To make the search non greedy, you need to use .{-} instead of .*:



          :%s/(.{-})here//





          share|improve this answer


























          • Haha, thats something new... Thanks it worked.

            – BladeMight
            Jan 19 at 9:40



















          2














          Another option is to use negative lookahead:



          :%s/v^((here)@!.)* here//


          v is used for very magic to avoid escaping all over in regex.






          share|improve this answer






























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            3














            As stated there, you can't add the ? char in vim after the asterix.
            To make the search non greedy, you need to use .{-} instead of .*:



            :%s/(.{-})here//





            share|improve this answer


























            • Haha, thats something new... Thanks it worked.

              – BladeMight
              Jan 19 at 9:40
















            3














            As stated there, you can't add the ? char in vim after the asterix.
            To make the search non greedy, you need to use .{-} instead of .*:



            :%s/(.{-})here//





            share|improve this answer


























            • Haha, thats something new... Thanks it worked.

              – BladeMight
              Jan 19 at 9:40














            3












            3








            3







            As stated there, you can't add the ? char in vim after the asterix.
            To make the search non greedy, you need to use .{-} instead of .*:



            :%s/(.{-})here//





            share|improve this answer















            As stated there, you can't add the ? char in vim after the asterix.
            To make the search non greedy, you need to use .{-} instead of .*:



            :%s/(.{-})here//






            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Jan 19 at 9:45

























            answered Jan 19 at 9:37









            YoricYoric

            1,2002810




            1,2002810













            • Haha, thats something new... Thanks it worked.

              – BladeMight
              Jan 19 at 9:40



















            • Haha, thats something new... Thanks it worked.

              – BladeMight
              Jan 19 at 9:40

















            Haha, thats something new... Thanks it worked.

            – BladeMight
            Jan 19 at 9:40





            Haha, thats something new... Thanks it worked.

            – BladeMight
            Jan 19 at 9:40













            2














            Another option is to use negative lookahead:



            :%s/v^((here)@!.)* here//


            v is used for very magic to avoid escaping all over in regex.






            share|improve this answer




























              2














              Another option is to use negative lookahead:



              :%s/v^((here)@!.)* here//


              v is used for very magic to avoid escaping all over in regex.






              share|improve this answer


























                2












                2








                2







                Another option is to use negative lookahead:



                :%s/v^((here)@!.)* here//


                v is used for very magic to avoid escaping all over in regex.






                share|improve this answer













                Another option is to use negative lookahead:



                :%s/v^((here)@!.)* here//


                v is used for very magic to avoid escaping all over in regex.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Jan 19 at 9:45









                anubhavaanubhava

                524k46323397




                524k46323397















                    Popular posts from this blog

                    Homophylophilia

                    Updating UILabel text programmatically using a function

                    Cloud Functions - OpenCV Videocapture Read method fails for larger files from cloud storage