develooper Front page | perl.beginners | Postings from March 2002

Re: help me with a better backstepper?

Thread Previous | Thread Next
From:
Jeff 'japhy' Pinyan
Date:
March 6, 2002 11:30
Subject:
Re: help me with a better backstepper?
Message ID:
Pine.GSO.4.21.0203061428140.19417-100000@crusoe.crusoe.net
On Mar 6, M z said:

>I've written a little program to analyze lines that
>are longer than 70 characters, and if so, break at
>position 70 (if it is whitespace), if not whitespace
>(i.e. is in the middle of a word) it steps back to the
>first whitespace and breaks there.

  s/(.{1,70})\s/$1\n/g;

That says "match between 1 and 70 characters (as many possible) and then a
piece of whitespace" and replace it with the same text, except convert the
whitespace into a newline.  And the /g modifier says "do it for all
occurrences".

-- 
Jeff "japhy" Pinyan      japhy@pobox.com      http://www.pobox.com/~japhy/
RPI Acacia brother #734   http://www.perlmonks.org/   http://www.cpan.org/
** Look for "Regular Expressions in Perl" published by Manning, in 2002 **
<stu> what does y/// stand for?  <tenderpuss> why, yansliterate of course.
[  I'm looking for programming work.  If you like my work, let me know.  ]


Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About