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

how to match the space Not begin from the start-of-line

Expand Messages
  • ginkgo
    Hello everyone, I want to know how to match the space that is not in the start of the line. for example sss sss ^^^^ ^ I just match the second part of the
    Message 1 of 7 , Jul 1 2:40 AM
    • 0 Attachment
      Hello everyone,
      I want to know how to match the space that is not in the start of
      the line.

      for example
      sss sss
      ^^^^ ^
      I just match the second part of the sample.
      Can anyone help me?

      regard
      ginkgo


      --~--~---------~--~----~------------~-------~--~----~
      You received this message from the "vim_use" maillist.
      For more information, visit http://www.vim.org/maillist.php
      -~----------~----~----~----~------~----~------~--~---
    • A. S. Budden
      ... How about: /^ s + S + zs s / - Search ^ - Start of the line s + - One or more spaces (replace + with * if you don t mind whether there are spaces)
      Message 2 of 7 , Jul 1 2:47 AM
      • 0 Attachment
        2009/7/1 ginkgo <mydorado@...>:
        >
        > Hello everyone,
        >  I want to know how to match the space that is not in the start of
        > the line.
        >
        > for example
        >    sss sss
        > ^^^^   ^
        > I just match the second part of the sample.
        > Can anyone help me?

        How about:

        /^\s\+\S\+\zs\s

        / - Search
        ^ - Start of the line
        \s\+ - One or more spaces (replace \+ with * if you don't mind whether
        there are spaces)
        \S\+ - One or more non-space characters
        \zs - Start the match from here (so ignore everything before)
        \s - A space

        Al

        --~--~---------~--~----~------------~-------~--~----~
        You received this message from the "vim_use" maillist.
        For more information, visit http://www.vim.org/maillist.php
        -~----------~----~----~----~------~----~------~--~---
      • Tim Chase
        ... You want the @
        Message 3 of 7 , Jul 1 2:52 AM
        • 0 Attachment
          > I want to know how to match the space that is not in the start of
          > the line.
          >
          > for example
          > sss sss
          > ^^^^ ^
          > I just match the second part of the sample.

          You want the "\@<!" modifier:

          \%(^\s*\)\@<!\s

          which "Matches with zero width if the preceding atom does NOT
          match just before what follows." as detailed at

          :help /\@<!

          In this case, the preceding atom is

          \%(^\s*\)

          or "whitespace at the beginning of the line".

          -tim



          --~--~---------~--~----~------------~-------~--~----~
          You received this message from the "vim_use" maillist.
          For more information, visit http://www.vim.org/maillist.php
          -~----------~----~----~----~------~----~------~--~---
        • ginkgo
          ... Thank for quick reply, you pattern work for this case. I think I do not say clear, the other example sss sss ss ^^^^ ^^ ^^ ^^ just match the
          Message 4 of 7 , Jul 1 3:15 AM
          • 0 Attachment
            On Jul 1, 5:47 pm, "A. S. Budden" <abud...@...> wrote:
            > 2009/7/1 ginkgo <mydor...@...>:
            >
            >
            >
            > > Hello everyone,
            > >  I want to know how to match the space that is not in the start of
            > > the line.
            >
            > > for example
            > >    sss sss
            > > ^^^^   ^
            > > I just match the second part of the sample.
            > > Can anyone help me?
            >
            > How about:
            >
            > /^\s\+\S\+\zs\s
            >
            > /    - Search
            > ^    - Start of the line
            > \s\+ - One or more spaces (replace \+ with * if you don't mind whether
            > there are spaces)
            > \S\+ - One or more non-space characters
            > \zs  - Start the match from here (so ignore everything before)
            > \s   - A space
            >
            > Al

            Thank for quick reply, you pattern work for this case.
            I think I do not say clear, the other example
            sss sss ss
            ^^^^ ^^ ^^ ^^

            just match the second part. I want to match the 2,3,4 part

            regard
            ginkgo
            --~--~---------~--~----~------------~-------~--~----~
            You received this message from the "vim_use" maillist.
            For more information, visit http://www.vim.org/maillist.php
            -~----------~----~----~----~------~----~------~--~---
          • ginkgo
            ... thanks Tim , I think your atom work well. I know the @
            Message 5 of 7 , Jul 1 3:18 AM
            • 0 Attachment
              On Jul 1, 5:52 pm, Tim Chase <v...@...> wrote:
              > >   I want to know how to match the space that is not in the start of
              > > the line.
              >
              > > for example
              > >     sss sss
              > > ^^^^   ^
              > > I just match the second part of the sample.
              >
              > You want the "\@<!" modifier:
              >
              >    \%(^\s*\)\@<!\s
              >
              > which "Matches with zero width if the preceding atom does NOT
              > match just before what follows." as detailed at
              >
              >    :help /\@<!
              >
              > In this case, the preceding atom is
              >
              >    \%(^\s*\)
              >
              > or "whitespace at the beginning of the line".
              >
              > -tim

              thanks Tim , I think your atom work well. I know the \@<! , but I use
              the \%(^\s\+\)\@<!\s ,
              can you tell me, why the \s\+ not work well, but the \s* work well

              regard
              ginkgo
              --~--~---------~--~----~------------~-------~--~----~
              You received this message from the "vim_use" maillist.
              For more information, visit http://www.vim.org/maillist.php
              -~----------~----~----~----~------~----~------~--~---
            • Tim Chase
              ... They should be nearly equiv., with the only difference being the + version *requires* that the line start with whitespace (one or more whitespace
              Message 6 of 7 , Jul 1 3:30 AM
              • 0 Attachment
                >>> I want to know how to match the space that is not in the start of
                >>> the line.
                >>> for example
                >>> sss sss
                >>> ^^^^ ^
                >>> I just match the second part of the sample.
                >>
                >> \%(^\s*\)\@<!\s
                >
                > thanks Tim , I think your atom work well. I know the \@<! , but I use
                > the \%(^\s\+\)\@<!\s ,
                > can you tell me, why the \s\+ not work well, but the \s* work well

                They should be nearly equiv., with the only difference being the
                "\+" version *requires* that the line start with whitespace (one
                or more whitespace characters) whereas the "*" version allows the
                line to start without -whitespace. This also finds *all* the
                non-leading whitespace on the line. If you want just the first
                space, A.S. Budden posed a good solution.

                -tim




                --~--~---------~--~----~------------~-------~--~----~
                You received this message from the "vim_use" maillist.
                For more information, visit http://www.vim.org/maillist.php
                -~----------~----~----~----~------~----~------~--~---
              • A. S. Budden
                ... Ah, sorry, I misunderstood. I think Tim has posted a good solution, but another option would be: / S @
                Message 7 of 7 , Jul 1 4:15 AM
                • 0 Attachment
                  2009/7/1 ginkgo <mydorado@...>:
                  > On Jul 1, 5:47 pm, "A. S. Budden" <abud...@...> wrote:
                  >> 2009/7/1 ginkgo <mydor...@...>:
                  >> > Hello everyone,
                  >> >  I want to know how to match the space that is not in the start of
                  >> > the line.
                  >>
                  >> > for example
                  >> >    sss sss
                  >> > ^^^^   ^
                  >> > I just match the second part of the sample.
                  >> > Can anyone help me?
                  >>
                  >> How about:
                  >>
                  >> /^\s\+\S\+\zs\s
                  >>
                  >> /    - Search
                  >> ^    - Start of the line
                  >> \s\+ - One or more spaces (replace \+ with * if you don't mind whether
                  >> there are spaces)
                  >> \S\+ - One or more non-space characters
                  >> \zs  - Start the match from here (so ignore everything before)
                  >> \s   - A space
                  >>
                  >> Al
                  >
                  > Thank for quick reply,  you pattern work for this case.
                  > I think I do not say clear, the other example
                  >    sss  sss   ss
                  > ^^^^   ^^   ^^  ^^
                  >
                  > just match the second part. I want to match the 2,3,4 part

                  Ah, sorry, I misunderstood. I think Tim has posted a good solution,
                  but another option would be:

                  /\S\@<=\s

                  \S - Non space
                  \@<= - Match with zero width if the \S is present
                  \s\+ - The spaces (or tabs) that you're looking for.

                  This will match any space characters that are preceded by something
                  that isn't a space character. You can probably also do:

                  \S\zs\s\+

                  Al

                  --~--~---------~--~----~------------~-------~--~----~
                  You received this message from the "vim_use" maillist.
                  For more information, visit http://www.vim.org/maillist.php
                  -~----------~----~----~----~------~----~------~--~---
                Your message has been successfully submitted and would be delivered to recipients shortly.