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

matchend() and \zs

Expand Messages
  • rameo
    My file - first line: an 91.010 &System.-sep010- I want to copy all numbers after -sep echo match(getline(1), sep zs d + ze- ) gives 23 as output.
    Message 1 of 11 , Apr 19 3:35 AM
    • 0 Attachment
      My file - first line:
      an 91.010 &System.-sep010- <Nop>

      I want to copy all numbers after -sep
      echo match(getline(1), 'sep\zs\d\+\ze-')
      gives 23 as output.
      All ok.

      but
      echo matchend(getline(1), 'sep\zs\d\+\ze-', 23)
      gives -1 as output.
      Why?

      If I remove "sep" before '\zs' it works.
      (echo matchend(getline(1), '\zs\d\+\ze-', 23)
      gives 26 as output.

      Does matchend not work with \zs?
      How can I resolve this problem?

      --
      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
    • Jürgen Krämer
      Hi, ... because the 23 that was returned from match() is the position of the first digit, not the position of sep . Thus you try to find sep zs d + ze- in a
      Message 2 of 11 , Apr 19 4:09 AM
      • 0 Attachment
        Hi,

        rameo wrote:
        > My file - first line:
        > an 91.010 &System.-sep010- <Nop>
        >
        > I want to copy all numbers after -sep
        > echo match(getline(1), 'sep\zs\d\+\ze-')
        > gives 23 as output.
        > All ok.
        >
        > but
        > echo matchend(getline(1), 'sep\zs\d\+\ze-', 23)
        > gives -1 as output.
        > Why?

        because the 23 that was returned from match() is the position of the
        first digit, not the position of 'sep'. Thus you try to find
        'sep\zs\d\+\ze-' in a string that for matchend() seems to consist only
        of

        010- <Nop>


        Regards,
        Jürgen

        --
        Sometimes I think the surest sign that intelligent life exists elsewhere
        in the universe is that none of it has tried to contact us. (Calvin)

        --
        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
      • rameo
        ... Thanks Jurgen, I use match() and matchend() to copy search matches to the clipboard or remove them out of the text. What can I do to make match() and
        Message 3 of 11 , Apr 19 7:04 AM
        • 0 Attachment
          On Thursday, April 19, 2012 1:09:10 PM UTC+2, jott...@... wrote:
          > Hi,
          >
          > rameo wrote:
          > > My file - first line:
          > > an 91.010 &System.-sep010- <Nop>
          > >
          > > I want to copy all numbers after -sep
          > > echo match(getline(1), 'sep\zs\d\+\ze-')
          > > gives 23 as output.
          > > All ok.
          > >
          > > but
          > > echo matchend(getline(1), 'sep\zs\d\+\ze-', 23)
          > > gives -1 as output.
          > > Why?
          >
          > because the 23 that was returned from match() is the position of the
          > first digit, not the position of 'sep'. Thus you try to find
          > 'sep\zs\d\+\ze-' in a string that for matchend() seems to consist only
          > of
          >
          > 010- <Nop>
          >
          >
          > Regards,
          > J�rgen
          >
          > --
          > Sometimes I think the surest sign that intelligent life exists elsewhere
          > in the universe is that none of it has tried to contact us. (Calvin)

          Thanks Jurgen,

          I use match() and matchend() to copy search matches to the clipboard
          or remove them out of the text.

          What can I do to make match() and matchend() work in order to copy p.e. the numbers after -sep?

          Regards,
          Raimond

          --
          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
        • Marcin Szamotulski
          ... It seems that echo matchend(getline(1), d + ze- , 23) should work just fine, where 23 is obtained by match(getline(1), sep zs s + ze- ) You do not need
          Message 4 of 11 , Apr 19 9:35 AM
          • 0 Attachment
            On 07:04 Thu 19 Apr , rameo wrote:
            > On Thursday, April 19, 2012 1:09:10 PM UTC+2, jott...@... wrote:
            > > Hi,
            > >
            > > rameo wrote:
            > > > My file - first line:
            > > > an 91.010 &System.-sep010- <Nop>
            > > >
            > > > I want to copy all numbers after -sep
            > > > echo match(getline(1), 'sep\zs\d\+\ze-')
            > > > gives 23 as output.
            > > > All ok.
            > > >
            > > > but
            > > > echo matchend(getline(1), 'sep\zs\d\+\ze-', 23)
            > > > gives -1 as output.
            > > > Why?
            > >
            > > because the 23 that was returned from match() is the position of the
            > > first digit, not the position of 'sep'. Thus you try to find
            > > 'sep\zs\d\+\ze-' in a string that for matchend() seems to consist only
            > > of
            > >
            > > 010- <Nop>
            > >
            > >
            > > Regards,
            > > J�rgen
            > >
            > > --
            > > Sometimes I think the surest sign that intelligent life exists elsewhere
            > > in the universe is that none of it has tried to contact us. (Calvin)
            >
            > Thanks Jurgen,
            >
            > I use match() and matchend() to copy search matches to the clipboard
            > or remove them out of the text.
            >
            > What can I do to make match() and matchend() work in order to copy p.e. the numbers after -sep?
            >
            > Regards,
            > Raimond
            >
            > --
            > 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

            It seems that
            echo matchend(getline(1), '\d\+\ze-', 23)
            should work just fine, where 23 is obtained by
            match(getline(1), 'sep\zs\s\+\ze-')
            You do not need to match sep twice.

            Best,
            Marcin


            --
            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
          • Ben Fritz
            ... I haven t looked in detail at your problem, but I wonder if you re running into the same issue as this recent thread:
            Message 5 of 11 , Apr 19 11:12 AM
            • 0 Attachment
              On Thursday, April 19, 2012 5:35:11 AM UTC-5, rameo wrote:
              > My file - first line:
              > an 91.010 &System.-sep010- <Nop>
              >
              > I want to copy all numbers after -sep
              > echo match(getline(1), 'sep\zs\d\+\ze-')
              > gives 23 as output.
              > All ok.
              >
              > but
              > echo matchend(getline(1), 'sep\zs\d\+\ze-', 23)
              > gives -1 as output.
              > Why?
              >
              > If I remove "sep" before '\zs' it works.
              > (echo matchend(getline(1), '\zs\d\+\ze-', 23)
              > gives 26 as output.
              >
              > Does matchend not work with \zs?
              > How can I resolve this problem?

              I haven't looked in detail at your problem, but I wonder if you're running into the same issue as this recent thread:

              https://groups.google.com/d/topic/vim_use/prE5uPDeETU/discussion

              In summary, giving a starting position to matchend() without giving a count treats the string as if the beginning of the string is at the starting position. So anything before the starting position cannot be used in the match, unless you provide a count as well.

              --
              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
            • rameo
              ... Hi Ben, Yes that s me. Thanks for the answer. What do you mean with provide a count? How do you provide a count to match() ... After all these match() and
              Message 6 of 11 , Apr 20 12:45 AM
              • 0 Attachment
                On Thursday, April 19, 2012 8:12:55 PM UTC+2, Ben Fritz wrote:
                > On Thursday, April 19, 2012 5:35:11 AM UTC-5, rameo wrote:
                > > My file - first line:
                > > an 91.010 &System.-sep010- <Nop>
                > >
                > > I want to copy all numbers after -sep
                > > echo match(getline(1), 'sep\zs\d\+\ze-')
                > > gives 23 as output.
                > > All ok.
                > >
                > > but
                > > echo matchend(getline(1), 'sep\zs\d\+\ze-', 23)
                > > gives -1 as output.
                > > Why?
                > >
                > > If I remove "sep" before '\zs' it works.
                > > (echo matchend(getline(1), '\zs\d\+\ze-', 23)
                > > gives 26 as output.
                > >
                > > Does matchend not work with \zs?
                > > How can I resolve this problem?
                >
                > I haven't looked in detail at your problem, but I wonder if you're running into the same issue as this recent thread:
                >
                > https://groups.google.com/d/topic/vim_use/prE5uPDeETU/discussion
                >
                > In summary, giving a starting position to matchend() without giving a count treats the string as if the beginning of the string is at the starting position. So anything before the starting position cannot be used in the match, unless you provide a count as well.

                Hi Ben,

                Yes that's me.

                Thanks for the answer.
                What do you mean with provide a count?
                How do you provide a count to match()

                ------

                After all these match() and matchend() problems, I'm trying to view if matches can be captured by using the submatch(0) and adding them to a register.
                Isn't this a bit dangerous because you have to return the submatch (in order to left the buffertext unchanged)?
                However I tested that it captures all matches whatever the regex is.

                --
                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
              • Ben Fritz
                ... Use the optional fourth argument. See :help match(), :help matchend(). -- You received this message from the vim_use maillist. Do not top-post! Type your
                Message 7 of 11 , Apr 20 8:47 AM
                • 0 Attachment
                  On Friday, April 20, 2012 2:45:28 AM UTC-5, rameo wrote:
                  >
                  > Thanks for the answer.
                  > What do you mean with provide a count?
                  > How do you provide a count to match()
                  >

                  Use the optional fourth argument. See :help match(), :help matchend().

                  --
                  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
                • Ben Fritz
                  ... submatch() only works inside a substitute() call or inside a :substitute command (:help sub-replace-expression). It says this explicitly in :help
                  Message 8 of 11 , Apr 20 8:52 AM
                  • 0 Attachment
                    On Friday, April 20, 2012 2:45:28 AM UTC-5, rameo wrote:
                    >
                    > After all these match() and matchend() problems, I'm trying to view if matches can be captured by using the submatch(0) and adding them to a register.
                    > Isn't this a bit dangerous because you have to return the submatch (in order to left the buffertext unchanged)?
                    > However I tested that it captures all matches whatever the regex is.

                    submatch() only works inside a substitute() call or inside a :substitute command (:help sub-replace-expression). It says this explicitly in :help submatch(). In the future, please read the help topics on the functions you are using before posting to the list.

                    In order to use the matched text, you can try matchstr() or matchlist() instead. Again, had you read the help for match(), you would have been directed to these functions.

                    --
                    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
                  • rameo
                    ... yes Ben, What do you think that I haven t read the help? I know that submatch() works only in a substitute command but that was not my question. I asked if
                    Message 9 of 11 , Apr 20 9:30 AM
                    • 0 Attachment
                      On Friday, April 20, 2012 5:52:37 PM UTC+2, Ben Fritz wrote:
                      > On Friday, April 20, 2012 2:45:28 AM UTC-5, rameo wrote:
                      > >
                      > > After all these match() and matchend() problems, I'm trying to view if matches can be captured by using the submatch(0) and adding them to a register.
                      > > Isn't this a bit dangerous because you have to return the submatch (in order to left the buffertext unchanged)?
                      > > However I tested that it captures all matches whatever the regex is.
                      >
                      > submatch() only works inside a substitute() call or inside a :substitute command (:help sub-replace-expression). It says this explicitly in :help submatch(). In the future, please read the help topics on the functions you are using before posting to the list.
                      >
                      > In order to use the matched text, you can try matchstr() or matchlist() instead. Again, had you read the help for match(), you would have been directed to these functions.

                      yes Ben,
                      What do you think that I haven't read the help?
                      I know that submatch() works only in a substitute command but that was not my question.
                      I asked if it is a bit dangerous to use submatch() to capture matches because it does a substitute in the text. However it seems to capture all, whatever regex.

                      And I've read also about match(), but not everything is so easy for me as it is for you as you are a longtime user ;)

                      --
                      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
                    • Ben Fritz
                      ... My apologies, I must have misunderstood your question about submatch(). I thought you had not read the help because: 1. I thought you were trying to use
                      Message 10 of 11 , Apr 20 11:51 AM
                      • 0 Attachment
                        On Friday, April 20, 2012 11:30:02 AM UTC-5, rameo wrote:
                        > On Friday, April 20, 2012 5:52:37 PM UTC+2, Ben Fritz wrote:
                        > > On Friday, April 20, 2012 2:45:28 AM UTC-5, rameo wrote:
                        > > >
                        > > > After all these match() and matchend() problems, I'm trying to view if matches can be captured by using the submatch(0) and adding them to a register.
                        > > > Isn't this a bit dangerous because you have to return the submatch (in order to left the buffertext unchanged)?
                        > > > However I tested that it captures all matches whatever the regex is.
                        > >
                        > > submatch() only works inside a substitute() call or inside a :substitute command (:help sub-replace-expression). It says this explicitly in :help submatch(). In the future, please read the help topics on the functions you are using before posting to the list.
                        > >
                        > > In order to use the matched text, you can try matchstr() or matchlist() instead. Again, had you read the help for match(), you would have been directed to these functions.
                        >
                        > yes Ben,
                        > What do you think that I haven't read the help?
                        > I know that submatch() works only in a substitute command but that was not my question.
                        > I asked if it is a bit dangerous to use submatch() to capture matches because it does a substitute in the text. However it seems to capture all, whatever regex.
                        >
                        > And I've read also about match(), but not everything is so easy for me as it is for you as you are a longtime user ;)

                        My apologies, I must have misunderstood your question about submatch(). I thought you had not read the help because:

                        1. I thought you were trying to use submatch() with a match() or matchend() call, since you did not mention using substitute()
                        2. You did not seem aware of the optional 4th argument to match() and matchend() which is documented in the help
                        3. You did not seem aware of matchstr() or matchlist(), which are linked from the help topic for match()

                        submatch() does not do any substitute by itself. It is as way to access a captured group in the replace text for a regular expression applied using the substitute() function, or the :substitute command, either of which can be manipulated to not actually make any textual changes.

                        --
                        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
                      • rameo
                        ... No problem. ad 1) yes you re right I didn t mention it but I thought it was clear that I mentioned submatch() as alternative of match(),matchend() ad 2)
                        Message 11 of 11 , Apr 20 12:28 PM
                        • 0 Attachment
                          On Friday, April 20, 2012 8:51:37 PM UTC+2, Ben Fritz wrote:
                          > On Friday, April 20, 2012 11:30:02 AM UTC-5, rameo wrote:
                          > > On Friday, April 20, 2012 5:52:37 PM UTC+2, Ben Fritz wrote:
                          > > > On Friday, April 20, 2012 2:45:28 AM UTC-5, rameo wrote:
                          > > > >
                          > > > > After all these match() and matchend() problems, I'm trying to view if matches can be captured by using the submatch(0) and adding them to a register.
                          > > > > Isn't this a bit dangerous because you have to return the submatch (in order to left the buffertext unchanged)?
                          > > > > However I tested that it captures all matches whatever the regex is.
                          > > >
                          > > > submatch() only works inside a substitute() call or inside a :substitute command (:help sub-replace-expression). It says this explicitly in :help submatch(). In the future, please read the help topics on the functions you are using before posting to the list.
                          > > >
                          > > > In order to use the matched text, you can try matchstr() or matchlist() instead. Again, had you read the help for match(), you would have been directed to these functions.
                          > >
                          > > yes Ben,
                          > > What do you think that I haven't read the help?
                          > > I know that submatch() works only in a substitute command but that was not my question.
                          > > I asked if it is a bit dangerous to use submatch() to capture matches because it does a substitute in the text. However it seems to capture all, whatever regex.
                          > >
                          > > And I've read also about match(), but not everything is so easy for me as it is for you as you are a longtime user ;)
                          >
                          > My apologies, I must have misunderstood your question about submatch(). I thought you had not read the help because:
                          >
                          > 1. I thought you were trying to use submatch() with a match() or matchend() call, since you did not mention using substitute()
                          > 2. You did not seem aware of the optional 4th argument to match() and matchend() which is documented in the help
                          > 3. You did not seem aware of matchstr() or matchlist(), which are linked from the help topic for match()
                          >
                          > submatch() does not do any substitute by itself. It is as way to access a captured group in the replace text for a regular expression applied using the substitute() function, or the :substitute command, either of which can be manipulated to not actually make any textual changes.

                          No problem.
                          ad 1) yes you're right I didn't mention it but I thought it was clear that I mentioned submatch() as alternative of match(),matchend()
                          ad 2) you're right. I was not aware of the 4th argument to match() and matchend()
                          ad 3) I know them. I often use matchstr().

                          I didn't know that submatch() doesn't do a substitute itself.
                          Yesterday I created a function which captures now what I want to capture using submatch() but I noted that the buffer is modified every time I capture the matches (using submatch()).

                          Btw.. thank you for your answers. I learn a lot of your replies.

                          --
                          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
                        Your message has been successfully submitted and would be delivered to recipients shortly.