Subj : RegExp Behaviour in FSE
To   : Deuce
From : Angus McLeod
Date : Thu Mar 02 2006 12:54 am

 Re: RegExp Behaviour in FSE
 By: Deuce to Angus McLeod on Wed Mar 01 2006 20:21:00

> That's pretty much how I'm leaning.. was just worried about the case where D
> User posted something about Dumb User and I wanted to quickly do a nice simp
> s/Dumb User/Idiot/g and it only matches one.  I mean... it's going to need t
> rewrap after a replacement anyways.

Hmmm.  /s makes "." match "\n" but that about "\s" ?  maybe you need to
do something like s/Dumb\sUser/Idiot/sg and let the \s match the
whitespace between "Dumb" and "User".

Look, people who want to use complex RE's will simply have to *learn*
complex RE's.

> iirc, in general, ^ and $ match the beginning an end of a *STRING* not
> a line.

Correct.  It doesn't apply to "lines" at all, unless of course, you store
that line in a string.

> So the m flag would make ^ and $ match lines.

Exactly.  Assuming that you treat a soft CR as a newline for the purposes
of ^ and $ same as a hard CR.

> The s flag wouldn't need any special handling at all since it merely expands
> what . matches to include newlines.  So your example would work as you expec
> with the m flag, and not match anything otherwise.  ie:
>
> $_="Two line\nParagraphs\n";
> print "No flags\n" if(/^Para/);
> print "m flag\n" if(/^Para/m);

Which seems to me to be intuitive.

> Further, if it included soft CRs, that would be an extra bit of whitespace
> where there "really" isnt.

Well, the separation between the last word on one line and the first word
on the next is in fact "whitespace".  Whether it is a space character or a
newline, it is still whitespace and matches \s.  So if you treated a soft
CR like a hard CR, you're doing the right thing, because (presumably) for
the auto-wordwrap to ahve kicked in, the user must have tyoed a space or
tab or something at that point in the input text.

To completely throw a spanner in the works:  Quoting.  How will you treat
something like

       > yada yada yada yada yada yada yada yada yada yada yada yada Dumb
       > User yada yada yada yada yada yada yada

when searching for /Dumb User/ or even /Dubm\s/User/m ?   ;-)



---
Playing: "Smokin Banana Peels" by "The Dead Milkmen"
        from the "Death Rides a Pale Cow" album
� Synchronet � Making sure Jason works OK at The ANJO BBS