in reply to Re^4: regexp: removing extra whitespace
in thread regexp: removing extra whitespace

In (?<=\s|^) \s is one character wide and ^ (an anchor) is 0 characters wide hence the "variable length" error.

Update: (?<=(?<=\s)|^) may work for you though.

True laziness is hard work

Replies are listed 'Best First'.
Re^6: regexp: removing extra whitespace
by ikegami (Patriarch) on Nov 05, 2011 at 01:23 UTC

    I'd go with

    (?<!\S)

    so

    s/[^\S \n]//g; s/(?<!\S) +| +(?!\S)//g; s/\n\n\K\n+//g;
Re^6: regexp: removing extra whitespace
by perlmax (Initiate) on Nov 04, 2011 at 23:24 UTC
    (?<=(?<=\s)|^) may work for you though.
    That fixed it! Thanks.