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

Re: regex: multiline search limited to blocks

Expand Messages
  • gumnos (Tim Chase)
    ... so ... Well, one option would be to use grouping operators. I m not sure if your SELECT will always be on the line preceeding the FROM line, but you might
    Message 1 of 6 , May 3, 2004
      > Unfortunately, MSSQL doesn't enforce a statement terminator (t-sql),
      so
      > the best I can do is assume that a statement is one block of lines
      > (containing no empty lines), so limit the search to the block. Now can
      > anyone help me create a regex for this? I presume I need to somehow
      > avoid \_$ appearing right after \_^ (with optional whitespace in
      > between), but I can't figureout how to express this.

      Well, one option would be to use grouping operators. I'm not sure if
      your SELECT will always be on the line preceeding the FROM line, but you
      might have something like

      /select\_.\{-}\(;\s*\_$\|\_^\s*\_$\)

      If you don't want to include the separator (either the ";" or the blank
      line), you can append the "\@=" marker to exclude the delimiter. This
      doesn't forgive semi-colons that may appear within strings like

      SELECT * FROM tblFoo WHERE tblFoo.bar = "your;mom"

      But might be able to be modified to include such. Maybe. :)

      -tim
    • Hari Krishna Dara
      ... Most probably not, the select could be followed by a number of field names one multiple lines. ... I definitely would like to specify a blank line as a
      Message 2 of 6 , May 3, 2004
        On Mon, 3 May 2004 at 1:29pm, gumnos (Tim Chase) wrote:

        > > Unfortunately, MSSQL doesn't enforce a statement terminator (t-sql),
        > so
        > > the best I can do is assume that a statement is one block of lines
        > > (containing no empty lines), so limit the search to the block. Now can
        > > anyone help me create a regex for this? I presume I need to somehow
        > > avoid \_$ appearing right after \_^ (with optional whitespace in
        > > between), but I can't figureout how to express this.
        >
        > Well, one option would be to use grouping operators. I'm not sure if
        > your SELECT will always be on the line preceeding the FROM line, but you
        > might have something like

        Most probably not, the select could be followed by a number of field
        names one multiple lines.

        >
        > /select\_.\{-}\(;\s*\_$\|\_^\s*\_$\)
        >
        > If you don't want to include the separator (either the ";" or the blank
        > line), you can append the "\@=" marker to exclude the delimiter. This
        > doesn't forgive semi-colons that may appear within strings like
        >
        > SELECT * FROM tblFoo WHERE tblFoo.bar = "your;mom"
        >
        > But might be able to be modified to include such. Maybe. :)
        >

        I definitely would like to specify a blank line as a separator, but how
        would the regex be? I think I got it (using the clues from your reply), I
        should use \(\_.\(\_^\s*\_$\)\@!\) as the atom in the place of \_[^;]
        which I used for oracle. This e.g., allows me to search for all the
        inserts that have a from clause:

        /insert\(\_.\(\_^\s*\_$\)\@!\)\+TOTABLE\(\_.\(\_^\s*\_$\)\@!\)\+from

        This would match something like:

        insert into TOTABLE (
        FIELD1,
        FIELD2,
        FIELD3,
        FIELD4)
        select
        val1,
        val2,
        val3,
        val4
        from
        FROMTABLE

        However, when I used the above regex, Vim had trouble searching for all
        the matches, sequentially. I first composed the regex to match the
        statement that I was interested in, then wanted to find all the
        statements that are similar in the same file. So I went to the start and
        started executing "n" command to see the matches one after the other,
        but figured it never matched the original statement. When I manually
        moved the cursor a couple of lines before the original statement and
        executed "n", it nicely matched, suggesting an issue with the distance
        from the cursor position.

        I did a little more research by using search() function instead of /
        command with the same regex. It behaved exactly the same, except that
        this time, I got the following error message instead of just keeping
        quite when there are no matches found.

        E363: pattern caused out-of-stack error

        Any idea if this is a problem with the regex that I used or a bug in
        Vim?

        Thank you,
        Hari




        __________________________________
        Do you Yahoo!?
        Win a $20,000 Career Makeover at Yahoo! HotJobs
        http://hotjobs.sweepstakes.yahoo.com/careermakeover
      • Hari Krishna Dara
        Can anyone please confirm that this is a bug in Vim? Will there be a fix? Thank you, Hari ... __________________________________ Do you Yahoo!? Win a $20,000
        Message 3 of 6 , May 10, 2004
          Can anyone please confirm that this is a bug in Vim? Will there be a
          fix?

          Thank you,
          Hari

          On Mon, 3 May 2004 at 12:01pm, Hari Krishna Dara wrote:

          >
          > On Mon, 3 May 2004 at 1:29pm, gumnos (Tim Chase) wrote:
          >
          > > > Unfortunately, MSSQL doesn't enforce a statement terminator (t-sql),
          > > so
          > > > the best I can do is assume that a statement is one block of lines
          > > > (containing no empty lines), so limit the search to the block. Now can
          > > > anyone help me create a regex for this? I presume I need to somehow
          > > > avoid \_$ appearing right after \_^ (with optional whitespace in
          > > > between), but I can't figureout how to express this.
          > >
          > > Well, one option would be to use grouping operators. I'm not sure if
          > > your SELECT will always be on the line preceeding the FROM line, but you
          > > might have something like
          >
          > Most probably not, the select could be followed by a number of field
          > names one multiple lines.
          >
          > >
          > > /select\_.\{-}\(;\s*\_$\|\_^\s*\_$\)
          > >
          > > If you don't want to include the separator (either the ";" or the blank
          > > line), you can append the "\@=" marker to exclude the delimiter. This
          > > doesn't forgive semi-colons that may appear within strings like
          > >
          > > SELECT * FROM tblFoo WHERE tblFoo.bar = "your;mom"
          > >
          > > But might be able to be modified to include such. Maybe. :)
          > >
          >
          > I definitely would like to specify a blank line as a separator, but how
          > would the regex be? I think I got it (using the clues from your reply), I
          > should use \(\_.\(\_^\s*\_$\)\@!\) as the atom in the place of \_[^;]
          > which I used for oracle. This e.g., allows me to search for all the
          > inserts that have a from clause:
          >
          > /insert\(\_.\(\_^\s*\_$\)\@!\)\+TOTABLE\(\_.\(\_^\s*\_$\)\@!\)\+from
          >
          > This would match something like:
          >
          > insert into TOTABLE (
          > FIELD1,
          > FIELD2,
          > FIELD3,
          > FIELD4)
          > select
          > val1,
          > val2,
          > val3,
          > val4
          > from
          > FROMTABLE
          >
          > However, when I used the above regex, Vim had trouble searching for all
          > the matches, sequentially. I first composed the regex to match the
          > statement that I was interested in, then wanted to find all the
          > statements that are similar in the same file. So I went to the start and
          > started executing "n" command to see the matches one after the other,
          > but figured it never matched the original statement. When I manually
          > moved the cursor a couple of lines before the original statement and
          > executed "n", it nicely matched, suggesting an issue with the distance
          > from the cursor position.
          >
          > I did a little more research by using search() function instead of /
          > command with the same regex. It behaved exactly the same, except that
          > this time, I got the following error message instead of just keeping
          > quite when there are no matches found.
          >
          > E363: pattern caused out-of-stack error
          >
          > Any idea if this is a problem with the regex that I used or a bug in
          > Vim?
          >
          > Thank you,
          > Hari
          >




          __________________________________
          Do you Yahoo!?
          Win a $20,000 Career Makeover at Yahoo! HotJobs
          http://hotjobs.sweepstakes.yahoo.com/careermakeover
        • Benji Fisher
          ... [snip] ... I tried the regex you mentioned. Just to be sure, here it is again: insert ( _. ( _^ s* _$ ) @! ) +TOTABLE ( _. ( _^ s* _$ ) @! ) +from I
          Message 4 of 6 , May 11, 2004
            On Mon, May 10, 2004 at 05:49:10PM -0700, Hari Krishna Dara wrote:
            > Can anyone please confirm that this is a bug in Vim? Will there be a
            > fix?
            >
            > Thank you,
            > Hari
            >
            [snip]
            > > /insert\(\_.\(\_^\s*\_$\)\@!\)\+TOTABLE\(\_.\(\_^\s*\_$\)\@!\)\+from
            > >
            > > This would match something like:
            > >
            > > insert into TOTABLE (
            > > FIELD1,
            > > FIELD2,
            > > FIELD3,
            > > FIELD4)
            > > select
            > > val1,
            > > val2,
            > > val3,
            > > val4
            > > from
            > > FROMTABLE
            > >
            > > However, when I used the above regex, Vim had trouble searching for all
            > > the matches, sequentially. I first composed the regex to match the
            > > statement that I was interested in, then wanted to find all the
            > > statements that are similar in the same file. So I went to the start and
            > > started executing "n" command to see the matches one after the other,
            > > but figured it never matched the original statement. When I manually
            > > moved the cursor a couple of lines before the original statement and
            > > executed "n", it nicely matched, suggesting an issue with the distance
            > > from the cursor position.
            > >
            > > I did a little more research by using search() function instead of /
            > > command with the same regex. It behaved exactly the same, except that
            > > this time, I got the following error message instead of just keeping
            > > quite when there are no matches found.
            > >
            > > E363: pattern caused out-of-stack error
            > >
            > > Any idea if this is a problem with the regex that I used or a bug in
            > > Vim?
            > >
            > > Thank you,
            > > Hari

            I tried the regex you mentioned. Just to be sure, here it is
            again:
            insert\(\_.\(\_^\s*\_$\)\@!\)\+TOTABLE\(\_.\(\_^\s*\_$\)\@!\)\+from
            I copied your snippet to a new buffer, removed the mail quotes ("> > "),
            and made a few copies, separated by blank lines. When I searched for
            the pattern, I found all the copies, including the one that began on
            Line 1. This is with vim 6.3a. Can you give a simple example of a file
            where there is a problem?

            I also had no trouble with using search(), but I am not all that
            surprised that you got an out-of-stack error with a real-life example.
            That '\_.' followed by '\(...\)\@!', all enclosed in '\(...\)\+' is one
            mean pattern! Maybe there is a way to do what you want without using a
            single regex...

            HTH --Benji Fisher
          • Hari Krishna Dara
            ... I am not surprised if it worked fine in your simple case, as it did match a few instances before failing even in my case. The file is huge with about
            Message 5 of 6 , May 11, 2004
              On Tue, 11 May 2004 at 12:34pm, Benji Fisher wrote:

              > On Mon, May 10, 2004 at 05:49:10PM -0700, Hari Krishna Dara wrote:
              > > Can anyone please confirm that this is a bug in Vim? Will there be a
              > > fix?
              > >
              > > Thank you,
              > > Hari
              > >
              > [snip]
              > > > /insert\(\_.\(\_^\s*\_$\)\@!\)\+TOTABLE\(\_.\(\_^\s*\_$\)\@!\)\+from
              > > >
              > > > This would match something like:
              > > >
              > > > insert into TOTABLE (
              > > > FIELD1,
              > > > FIELD2,
              > > > FIELD3,
              > > > FIELD4)
              > > > select
              > > > val1,
              > > > val2,
              > > > val3,
              > > > val4
              > > > from
              > > > FROMTABLE
              > > >
              > > > However, when I used the above regex, Vim had trouble searching for all
              > > > the matches, sequentially. I first composed the regex to match the
              > > > statement that I was interested in, then wanted to find all the
              > > > statements that are similar in the same file. So I went to the start and
              > > > started executing "n" command to see the matches one after the other,
              > > > but figured it never matched the original statement. When I manually
              > > > moved the cursor a couple of lines before the original statement and
              > > > executed "n", it nicely matched, suggesting an issue with the distance
              > > > from the cursor position.
              > > >
              > > > I did a little more research by using search() function instead of /
              > > > command with the same regex. It behaved exactly the same, except that
              > > > this time, I got the following error message instead of just keeping
              > > > quite when there are no matches found.
              > > >
              > > > E363: pattern caused out-of-stack error
              > > >
              > > > Any idea if this is a problem with the regex that I used or a bug in
              > > > Vim?
              > > >
              > > > Thank you,
              > > > Hari
              >
              > I tried the regex you mentioned. Just to be sure, here it is
              > again:
              > insert\(\_.\(\_^\s*\_$\)\@!\)\+TOTABLE\(\_.\(\_^\s*\_$\)\@!\)\+from
              > I copied your snippet to a new buffer, removed the mail quotes ("> > "),
              > and made a few copies, separated by blank lines. When I searched for
              > the pattern, I found all the copies, including the one that began on
              > Line 1. This is with vim 6.3a. Can you give a simple example of a file
              > where there is a problem?
              >
              > I also had no trouble with using search(), but I am not all that
              > surprised that you got an out-of-stack error with a real-life example.
              > That '\_.' followed by '\(...\)\@!', all enclosed in '\(...\)\+' is one
              > mean pattern! Maybe there is a way to do what you want without using a
              > single regex...
              >

              I am not surprised if it worked fine in your simple case, as it did
              match a few instances before failing even in my case. The file is huge
              with about 14,000 lines. If someone is interested in debugging the
              problem, I can probably send it personally after masking a few things in
              it.

              Not using a single regex is a good idea, as I figured I have to write a
              function anyway even for the above regex (I don't think I want to type
              it in everytime), so I will think about the alternatives. Thanks for the
              suggestion.

              Hari




              __________________________________
              Do you Yahoo!?
              Win a $20,000 Career Makeover at Yahoo! HotJobs
              http://hotjobs.sweepstakes.yahoo.com/careermakeover
            Your message has been successfully submitted and would be delivered to recipients shortly.