[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Re: Newlines included in bracket negation

Jesús Gabriel y Galán

10/26/2007 9:44:00 PM

On 10/26/07, Chris Morris <the.chrismo@gmail.com> wrote:
> Adding \n inside the brackets fixes it, I just wouldn't expect to have to do
> this since I didn't add the multiline mode option.
>
> require 'test/unit'
>
> class TestRE < Test::Unit::TestCase
> def test_newlines
> src = "happy\n\nbirthday"
> assert_equal("hday", src.scan(/h[^x\n]*?day/).to_s)
> end
> end

There's also something I don't understand, similar to the above.
I always thought that in a non-multiline regexp, the dot didn't match
newlines (\n), so I don't understand this:

irb(main):036:0> re = /(h)(.*)(day)/
=> /(h)(.*)(day)/
irb(main):037:0> "happy\n\nbirthday".match(re).captures
=> ["h", "", "day"]
irb(main):038:0> re = /(h)(.*)(day)/m
=> /(h)(.*)(day)/m
irb(main):039:0> "happy\n\nbirthday".match(re).captures
=> ["h", "appy\n\nbirth", "day"]

I thought the first case wouldn't match.
Can anyone shed some light?

Jesus.

10 Answers

Phrogz

10/26/2007 10:15:00 PM

0

On Oct 26, 3:43 pm, "Jes?s Gabriel y Gal?n" <jgabrielyga...@gmail.com>
wrote:

> There's also something I don't understand, similar to the above.
> I always thought that in a non-multiline regexp, the dot didn't match
> newlines (\n), so I don't understand this:
>
> irb(main):036:0> re = /(h)(.*)(day)/
> => /(h)(.*)(day)/
> irb(main):037:0> "happy\n\nbirthday".match(re).captures
> => ["h", "", "day"]
> irb(main):038:0> re = /(h)(.*)(day)/m
> => /(h)(.*)(day)/m
> irb(main):039:0> "happy\n\nbirthday".match(re).captures
> => ["h", "appy\n\nbirth", "day"]
>
> I thought the first case wouldn't match.
> Can anyone shed some light?

The last four characters of the word "birthday" match the regexp /
h.*day/, without crossing any newlines. Perhaps you were thinking of /
h.+day/, which does not match.

Jesús Gabriel y Galán

10/26/2007 10:34:00 PM

0

On 10/27/07, Phrogz <phrogz@mac.com> wrote:
> On Oct 26, 3:43 pm, "Jesús Gabriel y Galán" <jgabrielyga...@gmail.com>
> wrote:
>
> > There's also something I don't understand, similar to the above.
> > I always thought that in a non-multiline regexp, the dot didn't match
> > newlines (\n), so I don't understand this:
> >
> > irb(main):036:0> re = /(h)(.*)(day)/
> > => /(h)(.*)(day)/
> > irb(main):037:0> "happy\n\nbirthday".match(re).captures
> > => ["h", "", "day"]
> > irb(main):038:0> re = /(h)(.*)(day)/m
> > => /(h)(.*)(day)/m
> > irb(main):039:0> "happy\n\nbirthday".match(re).captures
> > => ["h", "appy\n\nbirth", "day"]
> >
> > I thought the first case wouldn't match.
> > Can anyone shed some light?
>
> The last four characters of the word "birthday" match the regexp /
> h.*day/, without crossing any newlines. Perhaps you were thinking of /
> h.+day/, which does not match.

I need more sleep, for sure. I was of course thinking on the first "h"
and the last "day". That explains it :-)

irb(main):043:0> "happy\n\nday".match(re).captures
NoMethodError: undefined method `captures' for nil:NilClass

Thanks,

Jesus.

7stud --

10/26/2007 11:24:00 PM

0

Jesús Gabriel y Galán wrote:
> On 10/27/07, Phrogz <phrogz@mac.com> wrote:
>> > => ["h", "", "day"]
>> h.+day/, which does not match.
> I need more sleep, for sure. I was of course thinking on the first "h"
> and the last "day". That explains it :-)
>

A clue was in the capture results:

rb(main):036:0> re = /(h)(.*)(day)/
=> /(h)(.*)(day)/
irb(main):037:0> "happy\n\nbirthday".match(re).captures
=> ["h", "", "day"]

The fact that the (.*) matched nothing was an indication that something
was amiss.

--
Posted via http://www.ruby-....

Rob Biedenharn

10/26/2007 11:48:00 PM

0

On Oct 26, 2007, at 7:23 PM, 7stud -- wrote:
> Jesús Gabriel y Galán wrote:
>> On 10/27/07, Phrogz <phrogz@mac.com> wrote:
>>>> => ["h", "", "day"]
>>> h.+day/, which does not match.
>> I need more sleep, for sure. I was of course thinking on the first
>> "h"
>> and the last "day". That explains it :-)
>
> A clue was in the capture results:
>
> rb(main):036:0> re = /(h)(.*)(day)/
> => /(h)(.*)(day)/
> irb(main):037:0> "happy\n\nbirthday".match(re).captures
> => ["h", "", "day"]
>
> The fact that the (.*) matched nothing was an indication that
> something
> was amiss.

Nothing amiss there at all. the * is match "zero or more times" and
so it is perfectly fine to match zero occurrences of any character
(except newline) between the 'h' and the 'day'

-Rob

Rob Biedenharn http://agileconsult...
Rob@AgileConsultingLLC.com



7stud --

10/27/2007 12:36:00 AM

0

Jesús Gabriel y Galán wrote:
>
> I was of course thinking on the first "h"
> and the last "day".

>>Rob Biedenharn wrote:
>>
>>Nothing amiss there at all.

Ok.
--
Posted via http://www.ruby-....

james g. keegan jr.

6/17/2011 12:10:00 PM

0

In article
<dcacc487-5e7b-4d8c-878e-e6bdbe7ffe46@u10g2000yqh.googlegroups.com>,
william mosco <wm5772@gmail.com> wrote:

> On Jun 17, 6:31?am, "james g. keegan jr." <jgkee...@gmail.com> wrote:
> > In article
> > <5077b611-4753-4085-be36-2c253321b...@k6g2000yqc.googlegroups.com>,
> > ?william mosco <wm5...@ymail.com> wrote:
> > > james g. keegan jr. wrote:
> > > > In article
> > > > <f34affff-37a8-440b-91d0-18f815332...@18g2000prd.googlegroups.com>,
> > > > ?william mosco <wm5...@ymail.com> wrote:
> >
> > > > > On Jun 16, 10:40?pm, "james g. keegan jr." <jgkee...@gmail.com>
> > > > > wrote:
> > > > > > In article
> > > > > > > > > what's my party asshole?
> >
> > > > > > > > the party of greed, corruption and disregard for humanity.
> >
> > > > > > > i'm not a democrat...
> >
> > > > > > indeed, nor did anyone ever claim you were.
> >
> > > > > actions speak louder than words.
> >
> > > > yours have created your net.reputation. *smirk*
> >
> > > You're just one person jimmy; you're free to think whatever but you
> > > don't speak for the net.
> >
> > don't try to change the subject and pretend referencing your
> > net.reputation was speaking for the net. stop lying billy.-
>
> did you take a net.poll?

you continue to earn your net.reputation.

james g. keegan jr.

6/17/2011 12:11:00 PM

0

In article
<d2ad77cc-e786-4b1e-9907-5c4c89a10b43@q30g2000yqb.googlegroups.com>,
william mosco <wm5772@gmail.com> wrote:

> On Jun 17, 6:30?am, "james g. keegan jr." <jgkee...@gmail.com> wrote:
> > In article
> > <cb31c74d-28f5-48b6-a00b-86b7329a6...@w4g2000yqm.googlegroups.com>,
> > ?william mosco <wm5...@ymail.com> wrote:
> >
> >
> >
> >
> >
> > > james g. keegan jr. wrote:
> > > > In article
> > > > <f502ba74-fd41-4596-acb2-e1f6940bb...@o10g2000prn.googlegroups.com>,
> > > > ?william mosco <wm5...@ymail.com> wrote:
> >
> > > > > On Jun 16, 10:40?pm, "james g. keegan jr." <jgkee...@gmail.com>
> > > > > wrote:
> > > > > > In article
> > > > > > <8363db25-721f-427b-a9b3-0f69a18b0...@z37g2000yqb.googlegroups.com>,
> > > > > > ?william mosco <wm5...@ymail.com> wrote:
> >
> > > > > > > On Jun 16, 7:51?am, "james g. keegan jr." <jgkee...@gmail.com>
> > > > > > > wrote:
> > > > > > > > In article <vjtkv6h73ve14duaqv0kd10q0n11np9...@4ax.com>,
> > > > > > > > ?Steve <stevencan...@yahooooo.com> wrote:
> > > > > > > > > On Thu, 16 Jun 2011 21:13:35 +0000 (UTC), "6075 Dead, 1218
> > > > > > > > > since
> > > > > > > > > 1/20/09" <d...@gone.com> wrote:
> > > > > > > > > >>> > > thank god you said that.
> > > > > > > > > >>> > > now i can safely feel that he'll not resign.- Hide
> > > > > > > > > >>> > > quoted
> > > > > > > > > >>> > > text -
> >
> > > > > > > > > >>> > ha ha ha ha ha ha ha!!!! ? within the time i
> > > > > > > > > >>> > predicted.
> >
> > > > > > > > > >>> that you did. one more strike against people.-
> >
> > > > > > > > > >> lighten up jimmy... ?he's a creep and he should go. ?i
> > > > > > > > > >> personally wanted him to stay so i could continue to
> > > > > > > > > >> laugh at him..
> >
> > > > > > > > > >Wierd. ?I don't see you laughing at all the creeps that
> > > > > > > > > >infest your party, Billy Moscow.
> >
> > > > > > > > > It's OK for Jamieson to be bitter.. ? Really, it is,
> > > > > > > > > after all, he's not going to get that free health care to
> > > > > > > > > go along with his welfare ?and food stamps.
> >
> > > > > > > > it's always amusing to watch people like billy to humiliate
> > > > > > > > themselves even more effectively than do their
> > > > > > > > adversaries.- Hide quoted text -
> >
> > > > > > > oh, was he talking about me? ?didn't catch that
> >
> > > > > > you catch very little.
> >
> > > > > well i'm not so accustomed as to where lies are directed as you
> > > > > are...
> >
> > > > when you lie as often as you do it's probably much harder for you
> > > > to keep track.
> >
> > > The only lies during this recent exchange are from you
> >
> > your post was cut after your first new lie.
>
> you must told another one.


your post was cut after your first new lie.

james g. keegan jr.

6/17/2011 2:36:00 PM

0

In article
<89a9e7b2-91f3-4709-bdbf-52dbd958f83e@k13g2000vbv.googlegroups.com>,
pnyikos <nyikos2@bellsouth.net> wrote:

> On Jun 17, 1:19?am, "james g. keegan jr." <jgkee...@gmail.com> wrote:
> > In article
> > <f34affff-37a8-440b-91d0-18f815332...@18g2000prd.googlegroups.com>,
> > ?william mosco <wm5...@ymail.com> wrote:
> >
> > > On Jun 16, 10:40 pm, "james g. keegan jr." <jgkee...@gmail.com> wrote:
> > > > In article
> > > > <af3ef78b-810b-4053-9c6a-124e333ca...@j31g2000yqe.googlegroups.com>,
> > > > william mosco <wm5...@ymail.com> wrote:
> > > > >On Jun 16, 7:53 am, "james g. keegan jr." <jgkee...@gmail.com> wrote:
> > > > > >In article
> > > > > ><39fbddf0-367e-4d1f-90f2-b77b110b2...@gc3g2000vbb.googlegroups.com>,
> > > > > >william mosco <wm5...@ymail.com> wrote:
>
> > > > > > > what's my party asshole?
> >
> > > > > > the party of greed, corruption and disregard for humanity.
>
> Keegan cannot back that up

your post was cut at your first new lie, plagiarist

william mosco

6/17/2011 11:33:00 PM

0

On Jun 17, 6:30 am, "james g. keegan jr." <jgkee...@gmail.com> wrote:
> In article
> <cb31c74d-28f5-48b6-a00b-86b7329a6...@w4g2000yqm.googlegroups.com>,
>  william mosco <wm5...@ymail.com> wrote:
>
>
>
>
>
> > james g. keegan jr. wrote:
> > > In article
> > > <f502ba74-fd41-4596-acb2-e1f6940bb...@o10g2000prn.googlegroups.com>,
> > >  william mosco <wm5...@ymail.com> wrote:
>
> > > > On Jun 16, 10:40?pm, "james g. keegan jr." <jgkee...@gmail.com> wrote:
> > > > > In article
> > > > > <8363db25-721f-427b-a9b3-0f69a18b0...@z37g2000yqb.googlegroups.com>,
> > > > > ?william mosco <wm5...@ymail.com> wrote:
>
> > > > > > On Jun 16, 7:51?am, "james g. keegan jr." <jgkee...@gmail.com> wrote:
> > > > > > > In article <vjtkv6h73ve14duaqv0kd10q0n11np9...@4ax.com>,
> > > > > > > ?Steve <stevencan...@yahooooo.com> wrote:
> > > > > > > > On Thu, 16 Jun 2011 21:13:35 +0000 (UTC), "6075 Dead, 1218 since
> > > > > > > > 1/20/09" <d...@gone.com> wrote:
> > > > > > > > >>> > > thank god you said that.
> > > > > > > > >>> > > now i can safely feel that he'll not resign.- Hide quoted
> > > > > > > > >>> > > text -
>
> > > > > > > > >>> > ha ha ha ha ha ha ha!!!! ? within the time i
> > > > > > > > >>> > predicted.
>
> > > > > > > > >>> that you did. one more strike against people.-
>
> > > > > > > > >> lighten up jimmy... ?he's a creep and he should go. ?i
> > > > > > > > >> personally wanted him to stay so i could continue to
> > > > > > > > >> laugh at him..
>
> > > > > > > > >Wierd. ?I don't see you laughing at all the creeps that
> > > > > > > > >infest your party, Billy Moscow.
>
> > > > > > > > It's OK for Jamieson to be bitter.. ? Really, it is,
> > > > > > > > after all, he's not going to get that free health care to
> > > > > > > > go along with his welfare ?and food stamps.
>
> > > > > > > it's always amusing to watch people like billy to humiliate
> > > > > > > themselves even more effectively than do their
> > > > > > > adversaries.- Hide quoted text -
>
> > > > > > oh, was he talking about me? ?didn't catch that
>
> > > > > you catch very little.
>
> > > > well i'm not so accustomed as to where lies are directed as you
> > > > are...
>
> > > when you lie as often as you do it's probably much harder for you
> > > to keep track.
>
> > The only lies during this recent exchange are from you
>
> your post was cut after your first new lie.- Hide quoted text -
>
> - Show quoted text -

you must told another one.

pnyikos

6/18/2011 1:43:00 AM

0

On Jun 17, 1:19 am, "james g. keegan jr." <jgkee...@gmail.com> wrote:
> In article
> <f34affff-37a8-440b-91d0-18f815332...@18g2000prd.googlegroups.com>,
>  william mosco <wm5...@ymail.com> wrote:
>
> > On Jun 16, 10:40 pm, "james g. keegan jr." <jgkee...@gmail.com> wrote:
> > > In article
> > > <af3ef78b-810b-4053-9c6a-124e333ca...@j31g2000yqe.googlegroups.com>,
> > > william mosco <wm5...@ymail.com> wrote:
> > > >On Jun 16, 7:53 am, "james g. keegan jr." <jgkee...@gmail.com> wrote:
> > > > >In article
> > > > ><39fbddf0-367e-4d1f-90f2-b77b110b2...@gc3g2000vbb.googlegroups.com>,
> > > > >william mosco <wm5...@ymail.com> wrote:

> > > > > > what's my party asshole?
>
> > > > > the party of greed, corruption and disregard for humanity.

Keegan cannot back that up, nor can his henchman Fischer, who also
spews such crap about Mosco.

Nor does Keegan try below. He relies on the way of Goebbels (or was
it Hitler himself?) who said that if you repeat a lie big enough
often enough, people will believe it.

>
> > > > i'm not a democrat...
>
> > > indeed, nor did anyone ever claim you were.
>
> > actions speak louder than words.
>
> yours have created your net.reputation. *smirk*

The "net.reputation" you are smirking about is worthless as long as
you cannot back up that empty smirk with evidence against him. And no
one can help you to back it up, from all that I have seen.

And it is only because you and your henchmen and henchwomen have such
a stranglehold on talk.abortion that you are able to create a virtual
reality of "net.reputations" of people like Bill.

And when you consider what a piddling little newsgroup talk.abortion
has become, with fewer regulars than there are students in the linear
algebra (Math 544) course I am teaching this Summer I session, that
really puts Bill's "net.reputation" into perspective.

Peter Nyikos