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

Re: [NTS] regular expression to find anything up to two spaces in a row ...

Expand Messages
  • Axel Berger
    Don wrote: ... You don t specify how general you need it to be. There may be more than one of those several space markers or none and the marker may be more
    Message 1 of 13 , Jun 18, 2011
    • 0 Attachment
      Don wrote:>
      > I want to find and capture everything and anything unless until I
      > encounter two spaces in a row ...

      You don't specify how general you need it to be. There may be more than
      one of those several space markers or none and the marker may be more
      than two spaces in a row. And you will need to find more than one line,
      I think. This caters for all of these:

      ^!Jump TEXT_START
      :loop
      ^!Find "(?s)(.+?)( {2,})" RSTI1
      ^!IfError rest
      ^!Continue
      ;^!MoveCursor 2
      ^!Find "(?s)( {2,})" RSTI
      ^!Jump SELECT_END
      ^!Goto loop
      :rest
      ^!Find "(?s)(.+)" RSTI
      ^!Continue

      Axel
    • Don
      Hi Axel, It is part of a longer expression. It is on a single line. (.+?) {2,} Don t know why I was struggling I guess ... other than I was trying to say
      Message 2 of 13 , Jun 18, 2011
      • 0 Attachment
        Hi Axel,

        It is part of a longer expression. It is on a single line.
        (.+?) {2,}

        Don't know why I was struggling I guess ... other than I was trying to
        say "anything but two spaces". This works fine -- but is there a way to
        actually say anything but two spaces? Things inside of [ and ] continue
        to baffle me at the moment. How do I say not something specific?

        Thank you for the prompt help!

        On 6/18/2011 11:21 AM, Axel Berger wrote:
        > Don wrote:>
        >> I want to find and capture everything and anything unless until I
        >> encounter two spaces in a row ...
        >
        > You don't specify how general you need it to be. There may be more than
        > one of those several space markers or none and the marker may be more
        > than two spaces in a row. And you will need to find more than one line,
        > I think. This caters for all of these:
        >
        > ^!Jump TEXT_START
        > :loop
        > ^!Find "(?s)(.+?)( {2,})" RSTI1
        > ^!IfError rest
        > ^!Continue
        > ;^!MoveCursor 2
        > ^!Find "(?s)( {2,})" RSTI
        > ^!Jump SELECT_END
        > ^!Goto loop
        > :rest
        > ^!Find "(?s)(.+)" RSTI
        > ^!Continue
        >
        > Axel
        >
        >
        > ------------------------------------
        >
        > Fookes Software: http://www.fookes.com/
        > NoteTab website: http://www.notetab.com/
        > NoteTab Discussion Lists: http://www.notetab.com/groups.php
        >
        > ***
        > Yahoo! Groups Links
        >
        >
        >
        >
      • John Shotsky
        Negative classes work by individual characters only. You could change any instance of two spaces to a token character, then negate class that, but that s
        Message 3 of 13 , Jun 18, 2011
        • 0 Attachment
          Negative classes work by individual characters only. You could change any instance of two spaces to a token character,
          then negate class that, but that's probably even more work.



          Regards,

          John

          <http://recipetools.gotdns.com/> RecipeTools site

          <http://groups.yahoo.com/group/RecipeTools/> RecipeTools Yahoo group

          <http://shotsky.gotdns.com/index.htm> Beaverton Weather



          From: ntb-scripts@yahoogroups.com [mailto:ntb-scripts@yahoogroups.com] On Behalf Of Don
          Sent: Saturday, June 18, 2011 09:26
          To: ntb-scripts@yahoogroups.com
          Subject: Re: [NTS] regular expression to find anything up to two spaces in a row ...





          Hi Axel,

          It is part of a longer expression. It is on a single line.
          (.+?) {2,}

          Don't know why I was struggling I guess ... other than I was trying to
          say "anything but two spaces". This works fine -- but is there a way to
          actually say anything but two spaces? Things inside of [ and ] continue
          to baffle me at the moment. How do I say not something specific?

          Thank you for the prompt help!

          On 6/18/2011 11:21 AM, Axel Berger wrote:
          > Don wrote:>
          >> I want to find and capture everything and anything unless until I
          >> encounter two spaces in a row ...
          >
          > You don't specify how general you need it to be. There may be more than
          > one of those several space markers or none and the marker may be more
          > than two spaces in a row. And you will need to find more than one line,
          > I think. This caters for all of these:
          >
          > ^!Jump TEXT_START
          > :loop
          > ^!Find "(?s)(.+?)( {2,})" RSTI1
          > ^!IfError rest
          > ^!Continue
          > ;^!MoveCursor 2
          > ^!Find "(?s)( {2,})" RSTI
          > ^!Jump SELECT_END
          > ^!Goto loop
          > :rest
          > ^!Find "(?s)(.+)" RSTI
          > ^!Continue
          >
          > Axel
          >
          >
          > ------------------------------------
          >
          > Fookes Software: http://www.fookes.com/
          > NoteTab website: http://www.notetab.com/
          > NoteTab Discussion Lists: http://www.notetab.com/groups.php
          >
          > ***
          > Yahoo! Groups Links
          >
          >
          >
          >





          [Non-text portions of this message have been removed]
        • Eb
          Move the quatifier outside of the class, Inside the class you re just adding the {2} characters to the class. ([^ ]{2}) If you want to expand this to mean 2
          Message 4 of 13 , Jun 20, 2011
          • 0 Attachment
            Move the quatifier outside of the class, Inside the class you're just adding the "{2}" characters to the class.

            ([^ ]{2})

            If you want to expand this to mean 2 or more spaces, just change the quantifier to {2,}

            --- In ntb-scripts@yahoogroups.com, Don <don@...> wrote:
            >
            > I want to find and capture everything and anything unless until I
            > encounter two spaces in a row ...
            >
            > I was trying this:
            > ([^ {2}]*)
            >
          • Axel Berger
            ... Nope. What you suggest equals two instances of not space . What Don wants is anything but two spaces in row . Quite different. All your finds will have
            Message 5 of 13 , Jun 20, 2011
            • 0 Attachment
              Eb wrote:
              > Move the quatifier outside of the class, Inside the class you're
              > just adding the "{2}" characters to the class.
              > ([^ ]{2})

              Nope. What you suggest equals "two instances of 'not space'". What Don
              wants is "anything but two spaces in row". Quite different.

              All your finds will have a length of exactly two and they can't include
              even a single space.

              There really is no single-step solution for this, but then, as long as
              clips is doing all the work and I don't have to, I really don't mind how
              many steps it takes.

              Axel
            • Don
              I am actually exporting this one to another purpose, but testing in both notetab and regex buddy.
              Message 6 of 13 , Jun 20, 2011
              • 0 Attachment
                I am actually exporting this one to another purpose, but testing in both
                notetab and regex buddy.

                On 6/20/2011 2:33 PM, Axel Berger wrote:
                > Eb wrote:
                >> Move the quatifier outside of the class, Inside the class you're
                >> just adding the "{2}" characters to the class.
                >> ([^ ]{2})
                >
                > Nope. What you suggest equals "two instances of 'not space'". What Don
                > wants is "anything but two spaces in row". Quite different.
                >
                > All your finds will have a length of exactly two and they can't include
                > even a single space.
                >
                > There really is no single-step solution for this, but then, as long as
                > clips is doing all the work and I don't have to, I really don't mind how
                > many steps it takes.
                >
                > Axel
              • Eb
                Right you are. I started out commenting on the placement of quatifiers. Then I was on a roll, but forgot about the _not_ two spaces. ... Actually, I would
                Message 7 of 13 , Jun 21, 2011
                • 0 Attachment
                  Right you are.

                  I started out commenting on the placement of quatifiers.

                  Then I was on a roll, but forgot about the _not_ two spaces.

                  --- In ntb-scripts@yahoogroups.com, Axel Berger <Axel-Berger@...> wrote:
                  > Nope. What you suggest equals "two instances of 'not space'". What Don
                  > wants is "anything but two spaces in row". Quite different.
                  >
                  > All your finds will have a length of exactly two and they can't include
                  > even a single space.
                  >
                  > There really is no single-step solution for this, but then, as long


                  Actually, I would expect the assertion:

                  (?= )

                  to find a string ending in 2 spaces, without including the two spaces in the match.

                  Eb
                • Axel Berger
                  ... Yes, you re right and that s probably better than my ^!Find (?s)(.+?)( {2,}) RSTI1 but it has the same problem. Don specified ... which I took to mean
                  Message 8 of 13 , Jun 21, 2011
                  • 0 Attachment
                    Eb wrote:
                    > Actually, I would expect the assertion:
                    > (?= )
                    > to find a string ending in 2 spaces, without including the
                    > two spaces in the match.

                    Yes, you're right and that's probably better than my

                    ^!Find "(?s)(.+?)( {2,})" RSTI1

                    but it has the same problem. Don specified
                    > everything and anything unless until I
                    > encounter two spaces in a row ...
                    which I took to mean the two spaces may or may not occur, as is usual
                    when using negative classes. If they're certain to do, then things get
                    much easier.

                    Axel
                  • Don
                    Yes the two spaces are certain to occur :-) I am limited I supposed in my understanding so I didn t make the assumption you made. Now that you explain it like
                    Message 9 of 13 , Jun 21, 2011
                    • 0 Attachment
                      Yes the two spaces are certain to occur :-)

                      I am limited I supposed in my understanding so I didn't make the
                      assumption you made. Now that you explain it like that I guess it makes
                      sense. What I am trying to do is use two spaces as a delimiter in
                      essence. I will actually be discarding the spaces as unnecessary in
                      what I am doing.

                      Off to look up (?= ) and see what it means.

                      On 6/21/2011 7:54 PM, Axel Berger wrote:
                      > Eb wrote:
                      >> Actually, I would expect the assertion:
                      >> (?= )
                      >> to find a string ending in 2 spaces, without including the
                      >> two spaces in the match.
                      >
                      > Yes, you're right and that's probably better than my
                      >
                      > ^!Find "(?s)(.+?)( {2,})" RSTI1
                      >
                      > but it has the same problem. Don specified
                      >> everything and anything unless until I
                      >> encounter two spaces in a row ...
                      > which I took to mean the two spaces may or may not occur, as is usual
                      > when using negative classes. If they're certain to do, then things get
                      > much easier.
                      >
                      > Axel
                      >
                      >
                      > ------------------------------------
                      >
                      > Fookes Software: http://www.fookes.com/
                      > NoteTab website: http://www.notetab.com/
                      > NoteTab Discussion Lists: http://www.notetab.com/groups.php
                      >
                      > ***
                      > Yahoo! Groups Links
                      >
                      >
                      >
                      >
                    • Don
                      From Regex Buddy (my newest friend ...): Positive lookahead works just the same. q(?=u) matches a q that is followed by a u, without making the u part of the
                      Message 10 of 13 , Jun 21, 2011
                      • 0 Attachment
                        From Regex Buddy (my newest friend ...):

                        "Positive lookahead works just the same. q(?=u) matches a q that is
                        followed by a u, without making the u part of the match. The positive
                        lookahead construct is a pair of round brackets, with the opening
                        bracket followed by a question mark and an equals sign. You can use any
                        regular expression inside the lookahead. Any valid regular expression
                        can be used inside the lookahead."

                        If I understand correctly, I can then actually do this:
                        (?=( ))
                        and create a back-reference if I wish?

                        Learning as I go here :-) and it's fun. Thanks Axel and Eb!


                        On 6/21/2011 7:54 PM, Axel Berger wrote:
                        > Eb wrote:
                        >> Actually, I would expect the assertion:
                        >> (?= )
                        >> to find a string ending in 2 spaces, without including the
                        >> two spaces in the match.
                        >
                        > Yes, you're right and that's probably better than my
                        >
                        > ^!Find "(?s)(.+?)( {2,})" RSTI1
                        >
                        > but it has the same problem. Don specified
                        >> everything and anything unless until I
                        >> encounter two spaces in a row ...
                        > which I took to mean the two spaces may or may not occur, as is usual
                        > when using negative classes. If they're certain to do, then things get
                        > much easier.
                        >
                        > Axel
                        >
                        >
                        > ------------------------------------
                        >
                        > Fookes Software: http://www.fookes.com/
                        > NoteTab website: http://www.notetab.com/
                        > NoteTab Discussion Lists: http://www.notetab.com/groups.php
                        >
                        > ***
                        > Yahoo! Groups Links
                        >
                        >
                        >
                        >
                      • John Shotsky
                        [Off to look up (?= ) and see what it means.] I use it often. It is the inverse of K - which doesn t capture anything before, but it evaluates it. (?=), when
                        Message 11 of 13 , Jun 21, 2011
                        • 0 Attachment
                          [Off to look up (?= ) and see what it means.]

                          I use it often. It is the inverse of \K - which doesn't capture anything before, but it evaluates it. (?=), when used in
                          a regex, is exactly the same, meaning anything that follows is not captured, but is evaluated.



                          So, this:

                          "this that"

                          Run on:

                          ^!Replace "this\x20\K(?=that)" >> "with\x20" ARSW

                          Produces "this with that"

                          Pretty handy for inserting something without any capturing.

                          Regards,

                          John



                          From: ntb-scripts@yahoogroups.com [mailto:ntb-scripts@yahoogroups.com] On Behalf Of Don
                          Sent: Tuesday, June 21, 2011 18:23
                          To: ntb-scripts@yahoogroups.com
                          Subject: Re: [NTS] Re: regular expression to find anything up to two spaces in a row ...





                          Yes the two spaces are certain to occur :-)

                          I am limited I supposed in my understanding so I didn't make the
                          assumption you made. Now that you explain it like that I guess it makes
                          sense. What I am trying to do is use two spaces as a delimiter in
                          essence. I will actually be discarding the spaces as unnecessary in
                          what I am doing.

                          Off to look up (?= ) and see what it means.

                          On 6/21/2011 7:54 PM, Axel Berger wrote:
                          > Eb wrote:
                          >> Actually, I would expect the assertion:
                          >> (?= )
                          >> to find a string ending in 2 spaces, without including the
                          >> two spaces in the match.
                          >
                          > Yes, you're right and that's probably better than my
                          >
                          > ^!Find "(?s)(.+?)( {2,})" RSTI1
                          >
                          > but it has the same problem. Don specified
                          >> everything and anything unless until I
                          >> encounter two spaces in a row ...
                          > which I took to mean the two spaces may or may not occur, as is usual
                          > when using negative classes. If they're certain to do, then things get
                          > much easier.
                          >
                          > Axel
                          >
                          >
                          > ------------------------------------
                          >
                          > Fookes Software: http://www.fookes.com/
                          > NoteTab website: http://www.notetab.com/
                          > NoteTab Discussion Lists: http://www.notetab.com/groups.php
                          >
                          > ***
                          > Yahoo! Groups Links
                          >
                          >
                          >
                          >





                          [Non-text portions of this message have been removed]
                        • Art Kocsis
                          John, Not quite. Look ahead and look behind assertions are very useful, I agree but K and (?
                          Message 12 of 13 , Jun 22, 2011
                          • 0 Attachment
                            John,

                            Not quite. Look ahead and look behind assertions are very useful, I agree but
                            \K and (?<=...) [the positive look behind assertion] are NOT EXACTLY the
                            same. The big difference (and what makes \K so much better), is that the
                            escape sequence \K allows variable length sub patterns whereas the positive/
                            negative look ahead/look behind assertions all require fixed length sub
                            patterns.

                            Namaste', Art

                            At 06/21/2011 19:12, John wrote:
                            >[Off to look up (?= ) and see what it means.]
                            >
                            >I use it often. It is the inverse of \K - which doesn't capture anything
                            >before, but it evaluates it.
                            >(?=), when used in a regex, is exactly the same, meaning anything that
                            >follows is not captured,
                            > but is evaluated.
                          Your message has been successfully submitted and would be delivered to recipients shortly.