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

Assertion behavior - was - RE: [NTS] Can a Reg Exp handle 123 AND not a|b|c followed by x?

Expand Messages
  • John Shotsky
    Flo (and all) Attempting to use the negative assertion function discussed below, but with bewildering results. I have two versions of a clip. One works as
    Message 1 of 10 , May 16, 2012
    View Source
    • 0 Attachment
      Flo (and all)
      Attempting to use the negative assertion function discussed below, but with bewildering results.
      I have two versions of a clip. One works as expected, the other doesn't. I can't see why the difference.
      Here are the two versions. To run them, just comment one out and run the other.
      ;^!Replace "^(Notes)(?!::)" >> "Dir::$1" ARSW
      ^!Replace "^Notes(?!::)" >> "Dir::" ARSW

      The goal is to place a Dir:: tag in front of any Notes tag that is not followed by [::].
      Here is the text sample:
      Notes::Note1: The traditional way to prepare this dish does not call for the removal of the vein from the prawn.

      It appears to work in v6.2, but it was a bit erratic - there were times when it didn't work, but it seems to be working
      correctly now. I will be retesting to see if I can get it to fail again. But in version 7, the first clip always fails
      the negative assertion and thus places the Dir:: tag when it shouldn't.

      Can anyone see anything I'm doing wrong, or is this a regex bug?

      Regards,
      John
      RecipeTools Web Site: http://recipetools.gotdns.com/


      -----Original Message-----
      From: ntb-scripts@yahoogroups.com [mailto:ntb-scripts@yahoogroups.com] On Behalf Of John Shotsky
      Sent: Thursday, May 10, 2012 09:13
      To: ntb-scripts@yahoogroups.com
      Subject: RE: [NTS] Can a Reg Exp handle 123 AND not a|b|c followed by x?

      Flo,
      Thank you. Always nice to learn something new. I will play around with this until I have it fully internalized. I have
      needed this function quite a few times and have 'tokenized' and then used a character class instead. (And then
      untokenized.) This is obviously a better way to do it.

      Regards,
      John
      RecipeTools Web Site: <http://recipetools.gotdns.com/> http://recipetools.gotdns.com/

      From: ntb-scripts@yahoogroups.com [mailto:ntb-scripts@yahoogroups.com] On Behalf Of flo.gehrke
      Sent: Thursday, May 10, 2012 07:46
      To: ntb-scripts@yahoogroups.com
      Subject: Re: [NTS] Can a Reg Exp handle 123 AND not a|b|c followed by x?


      --- In ntb-scripts@yahoogroups.com <mailto:ntb-scripts%40yahoogroups.com> , "John Shotsky" <jshotsky@...> wrote:
      >
      > I am not understanding something here – The criteria was:
      > three characters that are *NOT* MON|TUE|WED|THU|FRI|SAT|SUN
      >
      > How is this avoiding those strings? I've wanted to do this text
      > that didn't contain a certain string on multiple occasions.
      >

      John,

      The second part of that RegEx...

      \((?!Mon|Tue|Wed|Thu|Fri|Sat|Sun).{3}\)

      matches an opening and a closing literal bracket '(...)' embracing three digits '.{3}' that are NOT 'Mon', 'Tue' etc, as
      Joy demanded.

      The 3-digit-days are excluded with a Negative Lookahead. Since a Lookahead doesn't consume any character, any different
      3-digit-string will match at the same position between the opening and the closing bracket. That's why, for example,..

      'John' is matched with '(?!Mary)John'

      that is: Find 'John' at a position where you don't see 'Mary' when looking ahead.

      Regards,
      Flo



      [Non-text portions of this message have been removed]



      ------------------------------------

      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
      Further testing shows that I didn t have the clips exactly the same in 6.2 and 7. In one case there is an [s?]on the end of notes, and in the other case there
      Message 2 of 10 , May 16, 2012
      View Source
      • 0 Attachment
        Further testing shows that I didn't have the clips exactly the same in 6.2 and 7. In one case there is an [s?]on the end
        of notes, and in the other case there isn't. It is when the question mark is present that the failure occurs in both 6.2
        and 7. But still, I would have expected it to work, especially because the 's' is present - so that condition should
        have been satisfied before the look behind started looking. So, the question for me, then, is how do I prevent this
        erroneous action in the lookbehind, since the s? term must be present?

        These are the two clips as they produce the error:
        ;^!Replace "^(Notes?)(?!::)" >> "Dir::$1" ARSW
        ^!Replace "^Notes?(?!::)" >> "Dir::" ARSW
        Regards,
        John
        RecipeTools Web Site: http://recipetools.gotdns.com/


        -----Original Message-----
        From: ntb-clips@yahoogroups.com [mailto:ntb-clips@yahoogroups.com] On Behalf Of John Shotsky
        Sent: Wednesday, May 16, 2012 18:05
        To: ntb-clips@yahoogroups.com
        Cc: ntb-scripts@yahoogroups.com
        Subject: [Clip] Assertion behavior - was - RE: [NTS] Can a Reg Exp handle 123 AND not a|b|c followed by x?

        Flo (and all)
        Attempting to use the negative assertion function discussed below, but with bewildering results.
        I have two versions of a clip. One works as expected, the other doesn't. I can't see why the difference.
        Here are the two versions. To run them, just comment one out and run the other.
        ;^!Replace "^(Notes)(?!::)" >> "Dir::$1" ARSW
        ^!Replace "^Notes(?!::)" >> "Dir::" ARSW

        The goal is to place a Dir:: tag in front of any Notes tag that is not followed by [::].
        Here is the text sample:
        Notes::Note1: The traditional way to prepare this dish does not call for the removal of the vein from the prawn.

        It appears to work in v6.2, but it was a bit erratic - there were times when it didn't work, but it seems to be working
        correctly now. I will be retesting to see if I can get it to fail again. But in version 7, the first clip always fails
        the negative assertion and thus places the Dir:: tag when it shouldn't.

        Can anyone see anything I'm doing wrong, or is this a regex bug?

        Regards,
        John
        RecipeTools Web Site: http://recipetools.gotdns.com/


        -----Original Message-----
        From: ntb-scripts@yahoogroups.com [mailto:ntb-scripts@yahoogroups.com] On Behalf Of John Shotsky
        Sent: Thursday, May 10, 2012 09:13
        To: ntb-scripts@yahoogroups.com
        Subject: RE: [NTS] Can a Reg Exp handle 123 AND not a|b|c followed by x?

        Flo,
        Thank you. Always nice to learn something new. I will play around with this until I have it fully internalized. I have
        needed this function quite a few times and have 'tokenized' and then used a character class instead. (And then
        untokenized.) This is obviously a better way to do it.

        Regards,
        John
        RecipeTools Web Site: <http://recipetools.gotdns.com/> http://recipetools.gotdns.com/

        From: ntb-scripts@yahoogroups.com [mailto:ntb-scripts@yahoogroups.com] On Behalf Of flo.gehrke
        Sent: Thursday, May 10, 2012 07:46
        To: ntb-scripts@yahoogroups.com
        Subject: Re: [NTS] Can a Reg Exp handle 123 AND not a|b|c followed by x?


        --- In ntb-scripts@yahoogroups.com <mailto:ntb-scripts%40yahoogroups.com> , "John Shotsky" <jshotsky@...> wrote:
        >
        > I am not understanding something here – The criteria was:
        > three characters that are *NOT* MON|TUE|WED|THU|FRI|SAT|SUN
        >
        > How is this avoiding those strings? I've wanted to do this text
        > that didn't contain a certain string on multiple occasions.
        >

        John,

        The second part of that RegEx...

        \((?!Mon|Tue|Wed|Thu|Fri|Sat|Sun).{3}\)

        matches an opening and a closing literal bracket '(...)' embracing three digits '.{3}' that are NOT 'Mon', 'Tue' etc, as
        Joy demanded.

        The 3-digit-days are excluded with a Negative Lookahead. Since a Lookahead doesn't consume any character, any different
        3-digit-string will match at the same position between the opening and the closing bracket. That's why, for example,..

        'John' is matched with '(?!Mary)John'

        that is: Find 'John' at a position where you don't see 'Mary' when looking ahead.

        Regards,
        Flo



        [Non-text portions of this message have been removed]



        ------------------------------------

        Fookes Software: http://www.fookes.com/
        NoteTab website: http://www.notetab.com/
        NoteTab Discussion Lists: http://www.notetab.com/groups.php

        ***
        Yahoo! Groups Links





        ------------------------------------

        Fookes Software: http://www.fookes.com/
        NoteTab website: http://www.notetab.com/
        NoteTab Discussion Lists: http://www.notetab.com/groups.php

        ***
        Yahoo! Groups Links
      • flo.gehrke
        ... These two clips pursue different goals. #1 replaces Note/Notes with Dir::Note resp. Dir::Notes whereas #2 removes Note/Notes and replaces it with
        Message 3 of 10 , May 17, 2012
        View Source
        • 0 Attachment
          --- In ntb-clips@yahoogroups.com, "John Shotsky" <jshotsky@...> wrote:
          >
          > Further testing shows that I didn't have the clips exactly the
          > same in 6.2 and 7. In one case there is an [s?]on the end
          > of notes, and in the other case there isn't...

          > These are the two clips as they produce the error:
          > ;^!Replace "^(Notes?)(?!::)" >> "Dir::$1" ARSW
          > ^!Replace "^Notes?(?!::)" >> "Dir::" ARSW

          These two clips pursue different goals. #1 replaces 'Note/Notes' with 'Dir::Note' resp. 'Dir::Notes' whereas #2 removes 'Note/Notes' and replaces it with 'Dir::'. So what is your intention?

          Why don't you give us a few sample lines with all possible variations showing the 'before' and 'after'?

          Regards,
          Flo
        • John Shotsky
          I have found the reason for the problems I was having with the negative assertions. (Thanks, Dio) The requirement was simply to add a Dir:: tag, or not, based
          Message 4 of 10 , May 17, 2012
          View Source
          • 0 Attachment
            I have found the reason for the problems I was having with the negative assertions. (Thanks, Dio) The requirement was
            simply to add a Dir:: tag, or not, based on whether there were two colons following the leading word 'Note' or 'Notes'.
            The problem was that it was always adding the Dir:: tag. The reason is the s? bit, which apparently gives the s back to
            the assertion, causing it to fail. My workaround was to tokenize the one case where I wanted nothing to happen, and then
            change all the rest.

            So, I changed Notes:: to [N]otes::, then ran a clip to change all remaining cases of Note/Notes to be preceded by Dir::.
            After, the [N] must be unprotected. I could have used a special symbol, but this works just as well. I use that as a
            method of protecting many things, and there's a global cleanup of \[(.)\] to $1 later anyway.

            Regards,
            John
            RecipeTools Web Site: <http://recipetools.gotdns.com/> http://recipetools.gotdns.com/

            From: ntb-clips@yahoogroups.com [mailto:ntb-clips@yahoogroups.com] On Behalf Of flo.gehrke
            Sent: Thursday, May 17, 2012 11:21
            To: ntb-clips@yahoogroups.com
            Subject: Re: [Clip] Assertion behavior - was - RE: [NTS] Can a Reg Exp handle 123 AND not a|b|c followed by x?


            --- In ntb-clips@yahoogroups.com <mailto:ntb-clips%40yahoogroups.com> , "John Shotsky" <jshotsky@...> wrote:
            >
            > Further testing shows that I didn't have the clips exactly the
            > same in 6.2 and 7. In one case there is an [s?]on the end
            > of notes, and in the other case there isn't...

            > These are the two clips as they produce the error:
            > ;^!Replace "^(Notes?)(?!::)" >> "Dir::$1" ARSW
            > ^!Replace "^Notes?(?!::)" >> "Dir::" ARSW

            These two clips pursue different goals. #1 replaces 'Note/Notes' with 'Dir::Note' resp. 'Dir::Notes' whereas #2 removes
            'Note/Notes' and replaces it with 'Dir::'. So what is your intention?

            Why don't you give us a few sample lines with all possible variations showing the 'before' and 'after'?

            Regards,
            Flo



            [Non-text portions of this message have been removed]
          • flo.gehrke
            ... Certainly not. ... Why tokenizing anything here? According to your message, we ve got lines like... Note abc -- insert Dir:: yes Notes def -- insert
            Message 5 of 10 , May 17, 2012
            View Source
            • 0 Attachment
              --- In ntb-clips@yahoogroups.com, "John Shotsky" <jshotsky@...> wrote:
              >
              > I have found the reason for the problems I was having with the
              > negative assertions. (...) The problem was that it was always
              > adding the Dir:: tag. The reason is the s? bit, which apparently
              > gives the s back to the assertion, causing it to fail.

              Certainly not.

              > My workaround was to tokenize the one case where I wanted nothing
              > to happen, and then change all the rest. So, I changed Notes::
              > to [N]otes::, then ran a clip to change all remaining cases of
              > Note/Notes to be preceded by Dir::. After, the [N] must be
              > unprotected. I could have used a special symbol, but this works
              > just as well...

              Why "tokenizing" anything here? According to your message, we've got lines like...

              Note abc -- insert 'Dir::' yes
              Notes def -- 'insert Dir::' yes
              Note::ghi -- insert 'Dir::' no
              Notes::jkl -- insert 'Dir::' no

              Why don't you just execute...

              ^!Replace "^(?=Notes?\b(?!::))" >> "Dir::" ARSW

              Regards,
              Flo
            • John Shotsky
              Brilliant! Works perfectly, and I can even understand it! I don t think I would ever have come up with that on my own, though. :-( Regards, John RecipeTools
              Message 6 of 10 , May 17, 2012
              View Source
              • 0 Attachment
                Brilliant! Works perfectly, and I can even understand it! I don't think I would ever have come up with that on my own,
                though. :-(

                Regards,
                John
                RecipeTools Web Site: <http://recipetools.gotdns.com/> http://recipetools.gotdns.com/

                From: ntb-clips@yahoogroups.com [mailto:ntb-clips@yahoogroups.com] On Behalf Of flo.gehrke
                Sent: Thursday, May 17, 2012 15:23
                To: ntb-clips@yahoogroups.com
                Subject: Re: [Clip] Assertion behavior - was - RE: [NTS] Can a Reg Exp handle 123 AND not a|b|c followed by x?


                --- In ntb-clips@yahoogroups.com <mailto:ntb-clips%40yahoogroups.com> , "John Shotsky" <jshotsky@...> wrote:
                >
                > I have found the reason for the problems I was having with the
                > negative assertions. (...) The problem was that it was always
                > adding the Dir:: tag. The reason is the s? bit, which apparently
                > gives the s back to the assertion, causing it to fail.

                Certainly not.

                > My workaround was to tokenize the one case where I wanted nothing
                > to happen, and then change all the rest. So, I changed Notes::
                > to [N]otes::, then ran a clip to change all remaining cases of
                > Note/Notes to be preceded by Dir::. After, the [N] must be
                > unprotected. I could have used a special symbol, but this works
                > just as well...

                Why "tokenizing" anything here? According to your message, we've got lines like...

                Note abc -- insert 'Dir::' yes
                Notes def -- 'insert Dir::' yes
                Note::ghi -- insert 'Dir::' no
                Notes::jkl -- insert 'Dir::' no

                Why don't you just execute...

                ^!Replace "^(?=Notes?\b(?!::))" >> "Dir::" ARSW

                Regards,
                Flo



                [Non-text portions of this message have been removed]
              • John Shotsky
                Apparently, I still don t understand how to use the negative assertion. I have an idea that I m trying to do something that can t be done the way I imagine it,
                Message 7 of 10 , May 29, 2012
                View Source
                • 0 Attachment
                  Apparently, I still don't understand how to use the negative assertion. I have an idea that I'm trying to do something
                  that can't be done the way I imagine it, but here is the issue:

                  Given a line like:
                  <<>>This is an input line with a colon on the end:
                  Output:
                  I want to insert S> after <<>> if and only if it isn't there AND the line ends with a colon.
                  <<>>S>This is an input line with a colon on the end:

                  I think the problem is that I'm doing a negative lookahead for the S> to NOT be there, then follow it with (?= .+:\R)
                  I copied the working example and was able to make it work but only when the trailing phrase was not present. I tried
                  various usages of parens with no luck. Maybe this isn't the best way to do it � In the past, I've simply used the
                  (S>\x20)? at the beginning, which has the effect of replacing them even if they are present.
                  So, what would be the best way to insert the text only when it's missing? I use this technique a LOT, meaning a LOT of
                  things get replaced even when they are already there, in order to catch the cases when it's not there. Obviously, this
                  is taking up a lot of processing time, which I'd like to reduce.

                  Regards,
                  John
                  RecipeTools Web Site: <http://recipetools.gotdns.com/> http://recipetools.gotdns.com/

                  From: ntb-clips@yahoogroups.com [mailto:ntb-clips@yahoogroups.com] On Behalf Of flo.gehrke
                  Sent: Thursday, May 17, 2012 15:23
                  To: ntb-clips@yahoogroups.com
                  Subject: Re: [Clip] Assertion behavior - was - RE: [NTS] Can a Reg Exp handle 123 AND not a|b|c followed by x?


                  --- In ntb-clips@yahoogroups.com <mailto:ntb-clips%40yahoogroups.com> , "John Shotsky" <jshotsky@...> wrote:
                  >
                  > I have found the reason for the problems I was having with the
                  > negative assertions. (...) The problem was that it was always
                  > adding the Dir:: tag. The reason is the s? bit, which apparently
                  > gives the s back to the assertion, causing it to fail.

                  Certainly not.

                  > My workaround was to tokenize the one case where I wanted nothing
                  > to happen, and then change all the rest. So, I changed Notes::
                  > to [N]otes::, then ran a clip to change all remaining cases of
                  > Note/Notes to be preceded by Dir::. After, the [N] must be
                  > unprotected. I could have used a special symbol, but this works
                  > just as well...

                  Why "tokenizing" anything here? According to your message, we've got lines like...

                  Note abc -- insert 'Dir::' yes
                  Notes def -- 'insert Dir::' yes
                  Note::ghi -- insert 'Dir::' no
                  Notes::jkl -- insert 'Dir::' no

                  Why don't you just execute...

                  ^!Replace "^(?=Notes?\b(?!::))" >> "Dir::" ARSW

                  Regards,
                  Flo



                  [Non-text portions of this message have been removed]
                • John Shotsky
                  Please disregard my question - I had a typo in my text line. (There was something after the colon.) So my test case now works. Regards, John RecipeTools Web
                  Message 8 of 10 , May 29, 2012
                  View Source
                  • 0 Attachment
                    Please disregard my question - I had a typo in my text line. (There was something after the colon.) So my test case now
                    works.

                    Regards,
                    John
                    RecipeTools Web Site: http://recipetools.gotdns.com/


                    -----Original Message-----
                    From: ntb-clips@yahoogroups.com [mailto:ntb-clips@yahoogroups.com] On Behalf Of John Shotsky
                    Sent: Tuesday, May 29, 2012 07:35
                    To: ntb-clips@yahoogroups.com
                    Subject: RE: [Clip] Assertion behavior - was - RE: [NTS] Can a Reg Exp handle 123 AND not a|b|c followed by x?

                    Apparently, I still don't understand how to use the negative assertion. I have an idea that I'm trying to do something
                    that can't be done the way I imagine it, but here is the issue:

                    Given a line like:
                    <<>>This is an input line with a colon on the end:
                    Output:
                    I want to insert S> after <<>> if and only if it isn't there AND the line ends with a colon.
                    <<>>S>This is an input line with a colon on the end:

                    I think the problem is that I'm doing a negative lookahead for the S> to NOT be there, then follow it with (?= .+:\R)
                    I copied the working example and was able to make it work but only when the trailing phrase was not present. I tried
                    various usages of parens with no luck. Maybe this isn't the best way to do it – In the past, I've simply used the
                    (S>\x20)? at the beginning, which has the effect of replacing them even if they are present.
                    So, what would be the best way to insert the text only when it's missing? I use this technique a LOT, meaning a LOT of
                    things get replaced even when they are already there, in order to catch the cases when it's not there. Obviously, this
                    is taking up a lot of processing time, which I'd like to reduce.

                    Regards,
                    John
                    RecipeTools Web Site: <http://recipetools.gotdns.com/> http://recipetools.gotdns.com/

                    From: ntb-clips@yahoogroups.com [mailto:ntb-clips@yahoogroups.com] On Behalf Of flo.gehrke
                    Sent: Thursday, May 17, 2012 15:23
                    To: ntb-clips@yahoogroups.com
                    Subject: Re: [Clip] Assertion behavior - was - RE: [NTS] Can a Reg Exp handle 123 AND not a|b|c followed by x?


                    --- In ntb-clips@yahoogroups.com <mailto:ntb-clips%40yahoogroups.com> , "John Shotsky" <jshotsky@...> wrote:
                    >
                    > I have found the reason for the problems I was having with the
                    > negative assertions. (...) The problem was that it was always
                    > adding the Dir:: tag. The reason is the s? bit, which apparently
                    > gives the s back to the assertion, causing it to fail.

                    Certainly not.

                    > My workaround was to tokenize the one case where I wanted nothing
                    > to happen, and then change all the rest. So, I changed Notes::
                    > to [N]otes::, then ran a clip to change all remaining cases of
                    > Note/Notes to be preceded by Dir::. After, the [N] must be
                    > unprotected. I could have used a special symbol, but this works
                    > just as well...

                    Why "tokenizing" anything here? According to your message, we've got lines like...

                    Note abc -- insert 'Dir::' yes
                    Notes def -- 'insert Dir::' yes
                    Note::ghi -- insert 'Dir::' no
                    Notes::jkl -- insert 'Dir::' no

                    Why don't you just execute...

                    ^!Replace "^(?=Notes?\b(?!::))" >> "Dir::" ARSW

                    Regards,
                    Flo



                    [Non-text portions of this message have been removed]



                    ------------------------------------

                    Fookes Software: http://www.fookes.com/
                    NoteTab website: http://www.notetab.com/
                    NoteTab Discussion Lists: http://www.notetab.com/groups.php

                    ***
                    Yahoo! Groups Links
                  • Axel Berger
                    ... As expected what you get from me is a primitive solution. What I frequently do in cases like this is insert the string regardless and the replace it with
                    Message 9 of 10 , May 29, 2012
                    View Source
                    • 0 Attachment
                      John Shotsky wrote:
                      > In the past, I've simply used the (S>\x20)? at the beginning,
                      > which has the effect of replacing them even if they are present.

                      As expected what you get from me is a primitive solution. What I
                      frequently do in cases like this is insert the string regardless and the
                      replace it with nothing, if it's double.

                      This repairs unescaped ampersands in URLs:
                      ^!Set %varURL%=^$StrReplace("&";"&";"^%varURL%";False;False)$
                      ^!Set
                      %varURL%=^$StrReplace("&amp;";"&";"^%varURL%";False;False)$

                      This comments or uncomments HTML:
                      ^!Select LINES
                      ^!InsertSelect <!-- ^P^$GetSelection$-->^P
                      ^!Replace "<!-- ^P<!-- ^P" >> "" HASTI
                      ^!Replace "-->^P-->^P" >> "" HASTI
                      ^!Goto EXIT

                      In all cases where the wrong thing is easy to find and easy to undo I
                      don't put effort into doing the right thing only. So why not

                      ^!Replace "^P<<>>S>S>" >> "^P<<>>S>" WASTI

                      Axel
                    • John Shotsky
                      Axel, I appreciate the ideas, but my goal is to not make any changes that are not needed, and to not make errors that have to be fixed. Some of my processes
                      Message 10 of 10 , May 29, 2012
                      View Source
                      • 0 Attachment
                        Axel,

                        I appreciate the ideas, but my goal is to not make any changes that are not needed, and to not make errors that have to
                        be fixed. Some of my processes run over 5 minutes, depending on the size of the input file, so not making any changes
                        that are unneeded, and not having to fix errors saves processing time. At some point, I need to find out which processes
                        are taking the most time, and see if I can find ways to speed them up.

                        But if I WAS to use the cleanup feature you described, I'd do it this way:
                        ^!Replace "^<<>>(S>\x20)\K\1" >> "" ARSW
                        Regards,
                        John
                        RecipeTools Web Site: <http://recipetools.gotdns.com/> http://recipetools.gotdns.com/

                        From: ntb-clips@yahoogroups.com [mailto:ntb-clips@yahoogroups.com] On Behalf Of Axel Berger
                        Sent: Tuesday, May 29, 2012 09:26
                        To: ntb-clips@yahoogroups.com
                        Subject: Re: [Clip] Assertion behavior - was - RE: [NTS] Can a Reg Exp handle 123 AND not a|b|c followed by x?


                        John Shotsky wrote:
                        > In the past, I've simply used the (S>\x20)? at the beginning,
                        > which has the effect of replacing them even if they are present.

                        As expected what you get from me is a primitive solution. What I
                        frequently do in cases like this is insert the string regardless and the
                        replace it with nothing, if it's double.

                        This repairs unescaped ampersands in URLs:
                        ^!Set %varURL%=^$StrReplace("&";"&";"^%varURL%";False;False)$
                        ^!Set
                        %varURL%=^$StrReplace("&amp;";"&";"^%varURL%";False;False)$

                        This comments or uncomments HTML:
                        ^!Select LINES
                        ^!InsertSelect <!-- ^P^$GetSelection$-->^P
                        ^!Replace "<!-- ^P<!-- ^P" >> "" HASTI
                        ^!Replace "-->^P-->^P" >> "" HASTI
                        ^!Goto EXIT

                        In all cases where the wrong thing is easy to find and easy to undo I
                        don't put effort into doing the right thing only. So why not

                        ^!Replace "^P<<>>S>S>" >> "^P<<>>S>" WASTI

                        Axel



                        [Non-text portions of this message have been removed]
                      Your message has been successfully submitted and would be delivered to recipients shortly.