Not greedy enough

Honestly, I really dislike regular expressions. Some people love them for
their terseness. I, on the other hand, being a pooh of very little brain,
spend far too many hair pulling hours just trying to get one of the dang
things right. Ugh.

Right now I'm working on this:

  /^[ ]*[-](.*\n)+.*\n/

Applied to:

  %Q{
    - xyz
    - abc

    - not this
  }

I want it to match just the first section, essentially

  " - xyz\n - abc\n\n".

But it's matching the whole string. Can any of you Regexp experts fill me in?

Thanks,
T.

Hi --

···

On Thu, 23 Sep 2004, trans. (T. Onoma) wrote:

Right now I'm working on this:

  /^*[-](.*\n)+.*\n/

Applied to:

  %Q{
    - xyz
    - abc

    - not this
  }

I want it to match just the first section, essentially

  " - xyz\n - abc\n\n".

But it's matching the whole string. Can any of you Regexp experts fill me in?

I think what you want is: match one or more consecutive occurrences
of <space>-<stuff>\n, stopping when one of them has an extra \n at the
end.

Try this and see if it's close to what you need:

  /(^\ *-.*\n)+\n/

David

--
David A. Black
dblack@wobblini.net

trans. (T. Onoma) schrieb:

Right now I'm working on this:

  /^*[-](.*\n)+.*\n/

Applied to:

  %Q{
    - xyz
    - abc

    - not this
  }

I want it to match just the first section, essentially

  " - xyz\n - abc\n\n".

But it's matching the whole string. Can any of you Regexp experts fill me in?

The repeating group in your regexp is (.*\n)+ and this matches every line. You have to enlarge this group as in /^( *-.*\n)+.*\n/

HTH

Pit

David A. Black wrote:

I think what you want is: match one or more consecutive occurrences
of <space>-<stuff>\n, stopping when one of them has an extra \n at the
end.

Try this and see if it's close to what you need:

  /(^\ *-.*\n)+\n/

Umm... in the regexp as in the other, isn't an m needed at the end?

Hal

/(^\ *-.*\n)+\ *\n/

Perfect. A "many hairs" thanks! :slight_smile:

T.

···

On Wednesday 22 September 2004 03:36 pm, David A. Black wrote:

I think what you want is: match one or more consecutive occurrences
of <space>-<stuff>\n, stopping when one of them has an extra \n at the
end.

Try this and see if it's close to what you need:

  /(^\ *-.*\n)+\n/

That makes sense. Thanks all!

T.

···

On Wednesday 22 September 2004 03:55 pm, Pit Capitain wrote:

The repeating group in your regexp is (.*\n)+ and this matches every line.
You have to enlarge this group as in /^( *-.*\n)+.*\n/

Hal Fulton wrote:

David A. Black wrote:

I think what you want is: match one or more consecutive occurrences
of <space>-<stuff>\n, stopping when one of them has an extra \n at the
end.

Try this and see if it's close to what you need:

  /(^\ *-.*\n)+\n/

Umm... in the regexp as in the other, isn't an m needed at the end?

No, sorry, ignore me. I was quite wrong.

Hal

Hi --

···

On Thu, 23 Sep 2004, Hal Fulton wrote:

David A. Black wrote:
> I think what you want is: match one or more consecutive occurrences
> of <space>-<stuff>\n, stopping when one of them has an extra \n at the
> end.
>
> Try this and see if it's close to what you need:
>
> /(^\ *-.*\n)+\n/

Umm... in the regexp as in the other, isn't an m needed at the end?

No, because if you put an /m, then the dot will match \n, and .* will
trample over the end of the lines. I'm using \n as a flag for
starting and stopping.

David

--
David A. Black
dblack@wobblini.net