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

Thanks for your response. I tried the regexp you posted and I'm still encountering a few problems. There are many lines that only contain a single space. Since there's still a space on the line it prevents the regexp from catching the \n{3,} occurrences. I should have specified in my original post that I need to catch all spaces that are preceded or followed by additional whitespace. Instead of just {space}{space} it should also check for {space}\s. How can I revise the regexp you posted to include that functionality? Document example after the regexp:
\n{space} \n{space} \n{space}
All of the tabs in the document appear after a new line and since I'm preserving the new line characters I'm not worried about replacing the tabs with a space. Any tabs found in the middle of a line would be accidental but I'd still like to check for them and remove them if found.

Replies are listed 'Best First'.
Re^3: regexp: removing extra whitespace
by ikegami (Patriarch) on Nov 04, 2011 at 20:52 UTC

    Since there's still a space on the line it prevents the regexp from catching the \n{3,} occurrences.

    There is no \n{3,} in my code. As for non empty line not getting deleted, that's consistent with what you asked. Are you now asking to consider lines with just whitespace to be empty?

    I need to catch all spaces that are preceded or followed by additional whitespace. Instead of just {space}{space} it should also check for {space}\s

    That makes no sense. That says that {space}{space} should be collapsed to a space (which happens) and that {space}{newline} should be collapsed to {space} (which contradicts what you did say and makes no sense).