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

Regexp problem

Expand Messages
  • Christof Boeckler
    Hi all, I have a problem with me 05: in a script I wrote 1 replace-string ([^ ] )} 1 but I get the following error: [Regex Error: Open class ([...])]
    Message 1 of 8 , Oct 28, 2005
    • 0 Attachment
      Hi all,

      I have a problem with me 05: in a script I wrote

      1 replace-string "\([^\\]\)}" "\1 "

      but I get the following error:

      [Regex Error: Open class ([...])]

      I ran the script in a buffer with Magic mode on, but it dit not work. I
      assume that the regexp is the problem, although it should be legal there
      right? (I did not change any modes, because I don't even know how that
      works.)

      Any suggestions? Apart from that: jasspa me ist the best editor ever!

      Gruß / Regards
      Christof

      --
      http://home.in.tum.de/~boeckler/ http://www.spiegel.de/zwiebelfisch
      Da sie sich für weise hielten, sind sie zu Narren geworden. Rö 1,22
    • Thomas Hundt
      Suggest you use isearch-forward and type your string one char at a time to test it out. (Offhand, my guess is the second backslash inside the [] is the
      Message 2 of 8 , Oct 28, 2005
      • 0 Attachment
        Suggest you use isearch-forward and type your string one char at a time
        to test it out. (Offhand, my guess is the second backslash inside the
        [] is the problem. It is escaping the ']' and so ME is not seeing it as
        an "end of class" token.)

        Viel Vergnuegen

        -Th



        Christof Boeckler wrote:
        > Hi all,
        >
        > I have a problem with me 05: in a script I wrote
        >
        > 1 replace-string "\([^\\]\)}" "\1 "
        >
        > but I get the following error:
        >
        > [Regex Error: Open class ([...])]
        >
        > I ran the script in a buffer with Magic mode on, but it dit not work. I
        > assume that the regexp is the problem, although it should be legal there
        > right? (I did not change any modes, because I don't even know how that
        > works.)
        >
        > Any suggestions? Apart from that: jasspa me ist the best editor ever!
        >
        > Gruß / Regards
        > Christof
        >
      • Jon Green
        ... The problem is the backslash escape character in a macro script. In a script the escape character is so for a single backslash you need two i.e. . For
        Message 3 of 8 , Oct 29, 2005
        • 0 Attachment
          Thomas Hundt wrote:
          > Suggest you use isearch-forward and type your string one char at a time
          > to test it out. (Offhand, my guess is the second backslash inside the
          > [] is the problem. It is escaping the ']' and so ME is not seeing it as
          > an "end of class" token.)
          >
          > Viel Vergnuegen
          >
          > -Th
          >

          The problem is the backslash escape character in a macro script. In a
          script the escape character is \ so for a single backslash you need two
          i.e. \\. For a double backslash you actually need 4 i.e. \\\\.

          So the macro language input of \\\\ enters the regex engine as \\. The
          regex engine also uses backslash as an escape so \\ => \ as required.

          Jon
        • Steven Phillips
          Christof, I believe the following is what you need: 1 replace-string ([^ ] )} 1 Lots and lots of s! Like the reference card, looking forward to
          Message 4 of 8 , Oct 29, 2005
          • 0 Attachment
            Christof,

            I believe the following is what you need:

            1 replace-string "\\([^\\\\]\\)}" "\\1 "

            Lots and lots of '\'s!

            Like the reference card, looking forward to the macro page,

            Steve

            > Subject: [jasspa] Regexp problem
            > From: Christof Boeckler <boeckler@...>
            > Date: Friday, October 28, 2005, 7:50:25 PM
            > To: jasspa@yahoogroups.com
            > Hi all,

            > I have a problem with me 05: in a script I wrote

            > 1 replace-string "\([^\\]\)}" "\1 "

            > but I get the following error:

            > [Regex Error: Open class ([...])]

            > I ran the script in a buffer with Magic mode on, but it dit not work. I
            > assume that the regexp is the problem, although it should be legal there
            > right? (I did not change any modes, because I don't even know how that
            > works.)

            > Any suggestions? Apart from that: jasspa me ist the best editor ever!

            > Gruß / Regards
            > Christof
          • Christof Boeckler
            ... I wonder whether that is also written in the documentation, because it seems new to me - although it perfectly works for me ... ... Maybe you have a
            Message 5 of 8 , Oct 29, 2005
            • 0 Attachment
              Jon Green schrieb:
              > The problem is the backslash escape character in a macro script. In a
              > script the escape character is \ so for a single backslash you need two
              > i.e. \\. For a double backslash you actually need 4 i.e. \\\\.

              I wonder whether that is also written in the documentation, because it
              seems new to me - although it perfectly works for me ...

              > So the macro language input of \\\\ enters the regex engine as \\. The
              > regex engine also uses backslash as an escape so \\ => \ as required.

              Maybe you have a similar solution to this problem: in a macro I use
              kill-region
              set-variable #l1 @y
              insert-string #l1

              but it inserts the region I killed two times (doubled).

              > Jon

              Thanks for the help so far!
              Gruß / Regards
              Christof Böckler

              --
              http://home.in.tum.de/~boeckler/ http://www.spiegel.de/zwiebelfisch
              Da sie sich für weise hielten, sind sie zu Narren geworden. Rö 1,22
            • Thomas Hundt
              ... It works correctly for me, inserting only ONE copy of the region: kill-region set-variable #l1 @y insert-string before insert-string #l1 insert-string
              Message 6 of 8 , Oct 29, 2005
              • 0 Attachment
                > Maybe you have a similar solution to this problem: in a macro I use
                > kill-region
                > set-variable #l1 @y
                > insert-string #l1
                >
                > but it inserts the region I killed two times (doubled).

                It works correctly for me, inserting only ONE copy of the region:

                kill-region
                set-variable #l1 @y
                insert-string "before"
                insert-string #l1
                insert-string "after"

                (in fact, it looks to the user like the strings "before" and "after" are
                inserted, and the rest is left alone)

                -Th
              • Christof Boeckler
                ... Hm, now I realized the problem is somewhere else: depending on the way you mark the region it either works or not. It works if you do it the standard way
                Message 7 of 8 , Oct 29, 2005
                • 0 Attachment
                  Thomas Hundt schrieb:
                  > It works correctly for me, inserting only ONE copy of the region:
                  >
                  > kill-region
                  > set-variable #l1 @y
                  > insert-string "before"
                  > insert-string #l1
                  > insert-string "after"
                  >
                  > (in fact, it looks to the user like the strings "before" and "after" are
                  > inserted, and the rest is left alone)

                  Hm, now I realized the problem is somewhere else: depending on the way
                  you mark the region it either works or not. It works if you do it the
                  standard way (set-mark + move cursor), but it doesn't work properly, if
                  you use either the mouse or the MS-ish shift-cursor way.

                  I think this problem lays deeper ...

                  > -Th

                  Gruß / Regards
                  Christof

                  --
                  http://home.in.tum.de/~boeckler/ http://www.spiegel.de/zwiebelfisch
                  Da sie sich für weise hielten, sind sie zu Narren geworden. Rö 1,22
                • Christof Boeckler
                  ... I consider this to be a serious bug - what do you think? Gruß / Regards Christof -- http://home.in.tum.de/~boeckler/ http://www.spiegel.de/zwiebelfisch Da
                  Message 8 of 8 , Nov 8, 2005
                  • 0 Attachment
                    Christof Boeckler schrieb:
                    > Hm, now I realized the problem is somewhere else: depending on the way
                    > you mark the region it either works or not. It works if you do it the
                    > standard way (set-mark + move cursor), but it doesn't work properly, if
                    > you use either the mouse or the MS-ish shift-cursor way.
                    >
                    > I think this problem lays deeper ...

                    I consider this to be a serious bug - what do you think?

                    Gruß / Regards
                    Christof

                    --
                    http://home.in.tum.de/~boeckler/ http://www.spiegel.de/zwiebelfisch
                    Da sie sich für weise hielten, sind sie zu Narren geworden. Rö 1,22
                  Your message has been successfully submitted and would be delivered to recipients shortly.