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

There is no \n{3,} in my code.

That was an abbreviation. It was quicker to type \n{3,} than "it doesn't catch the 3 or more consecutive new lines."

Here's what I need to accomplish with the regexp.
/\s(?<![ \n])/ /(?<=\s|^) | (?=\s|$)/ /\n\n\K\n+/
Unfortunately the second statement above doesn't work. I'm using perl v5.10.1 and it gives the following error when that statement is used.

"Variable length lookbehind not implemented in regex /(?<=\s|^) | (?=\s|$)/ at test.pl line 10."

Replies are listed 'Best First'.
Re^5: regexp: removing extra whitespace
by GrandFather (Saint) on Nov 04, 2011 at 21:41 UTC

    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

      I'd go with

      (?<!\S)

      so

      s/[^\S \n]//g; s/(?<!\S) +| +(?!\S)//g; s/\n\n\K\n+//g;
      (?<=(?<=\s)|^) may work for you though.
      That fixed it! Thanks.