[thelist] Perl - regular expressions
Mal Wins
malwinsc at yahoo.com
Sat Dec 8 21:01:25 CST 2001
--- Dean Mah <dmah at shaw.ca> wrote:
> This only works for the first couple of segments.
> Using the loop
> method it doesn't matter how long the text is, it
> will iterate through
> the entire thing and break it into <= 99 character
> segments.
>
I could be wrong but I got the impression it was for a
teaser line , about the only use I saw for it
immediately. 99 char pages, just don't see the point.
But no mention of skipping HTML tags so maybe he wants
it in chunks. Either way thats a sweet regex.
> You're right. So instead try something like:
>
> while ($var =~ /(.{1,99})[\s\n]/gs) {
> print "$1\n\n";
> }
>
> That will treat your string as a single line so the
> '.' will match
> newlines as well.
>
> Dean
That does do the trick. I tried it (mistakenly) with
the /m and overlooked the /s. Next time I'll look it
up.
__________________________________________________
Do You Yahoo!?
Send your FREE holiday greetings online!
http://greetings.yahoo.com
More information about the thelist
mailing list