Perl Regular expression remove double tabs, line breaks, white spaces
- by Scoox
Hi guys,
I want to write a perl script that removes double tabs, line breaks and white spaces.
What I have so far is:
$txt=~s/\r//gs;
$txt=~s/ +/ /gs;
$txt=~s/\t+/\t/gs;
$txt=~s/[\t\n]*\n/\n/gs;
$txt=~s/\n+/\n/gs;
But,
1. It's not beautiful. Should be possible to do that with far less regexps.
2. It just doesn't work and I really do not know why. It leaves some double tabs, white spaces and empty lines (i.e. lines with only a tab or whitespace)
I could solve it with a while, but that is very slow and ugly.
Any suggestions?