Loading ...
Sorry, an error occurred while loading the content.

Substitution words within a partial match range help

Expand Messages
  • David Fishburn
    Vim 7.3.758 I have the following string: match / %(if |elsif |unless |given |when |default ) / match / / nextgroup=perlElseIfError skip0 skip1 skip2 I
    Message 1 of 4 , Apr 18, 2013
    • 0 Attachment
      Vim 7.3.758

      I have the following string:
      'match /\%(if\|elsif\|unless\|given\|when\|default\)\>/ match /\<\>/  nextgroup=perlElseIfError skip0 skip1 skip2'

      I was hoping (using 1 or 2 substitution commands) to find all words less than or equal to 5 characters in length and remove them.

      But, these words have to be within "match /.../" tags.

      So, when completed, the string above should read:
      'match /\%(\|\|unless\|\|\|default\)\>/ match /\<\>/  nextgroup=perlElseIfError skip0 skip1 skip2'

      Notice the skip0, skip1, skip2 are not touched since they are not within the beginning "match /" and the ending "/" of the match.

      My best try was the following:
      >echo substitute( 'match /\%(if\|elsif\|unless\|given\|when\|default\)\>/ match /\<\>/  nextgroup=perlElseIfError skip0 skip1 skip2', '\<match /.\{-}\zs\<\w\{1,5}\>\ze.\{-}/ ', '', 'g' )

      But it only gets rid of the "if" at the start, and doesn't work on any of the other matches.

      TIA,
      David

      --
      --
      You received this message from the "vim_use" maillist.
      Do not top-post! Type your reply below the text you are replying to.
      For more information, visit http://www.vim.org/maillist.php
       
      ---
      You received this message because you are subscribed to the Google Groups "vim_use" group.
      To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@....
      For more options, visit https://groups.google.com/groups/opt_out.
       
       
    • Andy Wokula
      ... You could try the pattern / %(match /[^/]* ) @ -- Andy -- -- You received this message from the vim_use maillist. Do not top-post! Type
      Message 2 of 4 , Apr 18, 2013
      • 0 Attachment
        Am 18.04.2013 15:27, schrieb David Fishburn:
        > Vim 7.3.758
        >
        > I have the following string:
        > 'match /\%(if\|elsif\|unless\|given\|when\|default\)\>/ match /\<\>/
        > nextgroup=perlElseIfError skip0 skip1 skip2'
        >
        > I was hoping (using 1 or 2 substitution commands) to find all words less
        > than or equal to 5 characters in length and remove them.
        >
        > But, these words have to be within "match /.../" tags.
        >
        > So, when completed, the string above should read:
        > 'match /\%(\|\|unless\|\|\|default\)\>/ match /\<\>/
        > nextgroup=perlElseIfError skip0 skip1 skip2'
        >
        > Notice the skip0, skip1, skip2 are not touched since they are not within
        > the beginning "match /" and the ending "/" of the match.
        >
        > My best try was the following:
        >> echo substitute( 'match /\%(if\|elsif\|unless\|given\|when\|default\)\>/
        > match /\<\>/ nextgroup=perlElseIfError skip0 skip1 skip2', '\<match
        > /.\{-}\zs\<\w\{1,5}\>\ze.\{-}/ ', '', 'g' )
        >
        > But it only gets rid of the "if" at the start, and doesn't work on any of
        > the other matches.
        >
        > TIA,
        > David

        You could try the pattern
        /\%(match \/[^/]*\)\@<=\<\w\{1,5}\>

        --
        Andy

        --
        --
        You received this message from the "vim_use" maillist.
        Do not top-post! Type your reply below the text you are replying to.
        For more information, visit http://www.vim.org/maillist.php

        ---
        You received this message because you are subscribed to the Google Groups "vim_use" group.
        To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@....
        For more options, visit https://groups.google.com/groups/opt_out.
      • Ben Fritz
        ... I got it working *better* using @ ze. {-}/ But this also removes the second match in the line, so
        Message 3 of 4 , Apr 18, 2013
        • 0 Attachment
          On Thursday, April 18, 2013 8:27:36 AM UTC-5, David Fishburn wrote:
          > Vim 7.3.758
          >
          >
          > I have the following string:
          >
          > 'match /\%(if\|elsif\|unless\|given\|when\|default\)\>/ match /\<\>/  nextgroup=perlElseIfError skip0 skip1 skip2'
          >
          >
          >
          > I was hoping (using 1 or 2 substitution commands) to find all words less than or equal to 5 characters in length and remove them.
          >
          >
          > But, these words have to be within "match /.../" tags.
          >
          >
          >
          > So, when completed, the string above should read:
          >
          > 'match /\%(\|\|unless\|\|\|default\)\>/ match /\<\>/  nextgroup=perlElseIfError skip0 skip1 skip2'
          >
          >
          >
          > Notice the skip0, skip1, skip2 are not touched since they are not within the beginning "match /" and the ending "/" of the match.
          >
          >
          > My best try was the following:
          >
          > >echo substitute( 'match /\%(if\|elsif\|unless\|given\|when\|default\)\>/ match /\<\>/  nextgroup=perlElseIfError skip0 skip1 skip2', '\<match /.\{-}\zs\<\w\{1,5}\>\ze.\{-}/ ', '', 'g' )
          >
          >
          >
          > But it only gets rid of the "if" at the start, and doesn't work on any of the other matches.
          >
          >
          > TIA,
          > David

          I got it working *better* using \@<= instead of \zs:

          \%(\<match /.\{-}\)\@<=\<\w\{1,5}\>\ze.\{-}/

          But this also removes the second "match" in the line, so you'll need to refine it some more, using [^/] instead of . to avoid that the ending '/' is allowed to match the beginning pattern:

          \%(\<match /[^/]\{-}\)\@<=\<\w\{1,5}\>\ze.\{-}/

          Now I think it works as you intended.

          --
          --
          You received this message from the "vim_use" maillist.
          Do not top-post! Type your reply below the text you are replying to.
          For more information, visit http://www.vim.org/maillist.php

          ---
          You received this message because you are subscribed to the Google Groups "vim_use" group.
          To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@....
          For more options, visit https://groups.google.com/groups/opt_out.
        • David Fishburn
          ... Thanks Andy and Ben. Using these hints I was able to get something that met my needs. Much appreciated. David -- -- You received this message from the
          Message 4 of 4 , May 7 12:41 AM
          • 0 Attachment



            On Thu, Apr 18, 2013 at 11:07 AM, Ben Fritz <fritzophrenic@...> wrote:
            ...
             
            I got it working *better* using \@<= instead of \zs:

            \%(\<match /.\{-}\)\@<=\<\w\{1,5}\>\ze.\{-}/

            But this also removes the second "match" in the line, so you'll need to refine it some more, using [^/] instead of . to avoid that the ending '/' is allowed to match the beginning pattern:

            \%(\<match /[^/]\{-}\)\@<=\<\w\{1,5}\>\ze.\{-}/

            Now I think it works as you intended.

            Thanks Andy and Ben.

            Using these hints I was able to get something that met my needs.

            Much appreciated.
            David

            --
            --
            You received this message from the "vim_use" maillist.
            Do not top-post! Type your reply below the text you are replying to.
            For more information, visit http://www.vim.org/maillist.php
             
            ---
            You received this message because you are subscribed to the Google Groups "vim_use" group.
            To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@....
            For more options, visit https://groups.google.com/groups/opt_out.
             
             
          Your message has been successfully submitted and would be delivered to recipients shortly.