in reply to goto() in regexes

Here's a simple substitution that inserts a newline every 80 characters, or at the end of the previous word. ('word' here is a sequence of non-whitespace characters, since that's usually what you want for wrapping.) s/\G(.{1,80})(?<=\S)\s+/$1\n/gm;

Replies are listed 'Best First'.
(MeowChow) Re2: goto() in regexes
by MeowChow (Vicar) on Aug 28, 2001 at 00:56 UTC
    I don't think the look-behind assertion and anchor are necessary (the anchor actually causes it to terminate early on certain boundary cases with newlines):
    s/(.{0,79}\S\s+)/$1\n/gm
    ... I could be wrong :)
       MeowChow                                   
                   s aamecha.s a..a\u$&owag.print
Re: Re: goto() in regexes
by japhy (Canon) on Aug 27, 2001 at 21:15 UTC
    Oh, ****.

    _____________________________________________________
    Jeff[japhy]Pinyan: Perl, regex, and perl hacker.
    s++=END;++y(;-P)}y js++=;shajsj<++y(p-q)}?print:??;