On Jul 29, KEVIN ZEMBOWER said: >Would anyone help me write a program which would transform these >documents? I'm trying to find all instances of a single newline, and >remove it, either inserting or removing space characters around where it >was to leave just one space between what was the two lines. I also need >to substitute a single newline for two or more consecutive newlines, >whether or not they're separated by whitespace characters.
I just realized I could make the regex much simpler: s{([^\S\n]*\n\s*)}{ my $ws = $1; if (($ws =~ tr/\n//) == 1) { " " } else { "\n" } }eg; In fact, you could even use s{(\s*\n\s*)}{...}eg; if you don't mind some occasional backtracking. And, in recent versions of Perl, you can use the $DIGIT vars in a non-modifying tr///, so you could do: # voila! $text =~ s/(\s*\n\s*)/($1 =~ tr!\n!!) == 1 ? " " : "\n"/eg; -- Jeff "japhy" Pinyan [EMAIL PROTECTED] http://www.pobox.com/~japhy/ RPI Acacia brother #734 http://www.perlmonks.org/ http://www.cpan.org/ ** Look for "Regular Expressions in Perl" published by Manning, in 2002 ** <stu> what does y/// stand for? <tenderpuss> why, yansliterate of course. [ I'm looking for programming work. If you like my work, let me know. ] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]