Find Blank Lines Using Perl Style Regexes

Find, replace, find in files, replace in files, regular expressions

Find Blank Lines Using Perl Style Regexes

Postby glen_ap » Mon Jul 10, 2006 6:30 pm

Hi,

I prefer to use Perl style regular expressions, however a simple regex that I used prior the Boost regex library was to search for blank lines.

Here is the search string when using Unix style (not Perl style):
"^\p"

Here is the UE regex style (from the FAQ):
"^p$"

Here is what I thought the Perl style should be:
"^\n"

But that doesn't work. I get a "Search string not found." message.

I have also tried with no success:
"\n\n"
"\n$"
"^\n$"

I have read the Boost documentation here:
http://www.boost.org/libs/regex/doc/syntax_perl.html

But I can't figure out what the syntax should be. Can anyone help?

Thanks!
Glen
User avatar
glen_ap
Newbie
 
Posts: 4
Joined: Tue Oct 11, 2005 11:00 pm

Re: Find Blank Lines Using Perl Style Regexes

Postby Mofi » Tue Jul 11, 2006 3:48 pm

\n matches only the linefeed character (hex 0A). If you see in the status bar at bottom of the UltraEdit window for the current file the word DOS, your file is loaded and edited with DOS line terminations carriage return + linefeed. So you have to use \r\n which matches 0D 0A. So try ^\r\n or better ^\r*\n.

See also Deleting blank lines using Perl regular expressions. Some problems reported at this forum thread are already fixed, but some Perl problems still exist with current version 12.10a.
User avatar
Mofi
Grand Master
Grand Master
 
Posts: 4064
Joined: Thu Jul 29, 2004 11:00 pm
Location: Vienna

Re: Find Blank Lines Using Perl Style Regexes

Postby glen_ap » Tue Jul 11, 2006 11:03 pm

Mofi wrote:So you have to use \r\n which matches 0D 0A.

Thanks! Worked like a charm.
User avatar
glen_ap
Newbie
 
Posts: 4
Joined: Tue Oct 11, 2005 11:00 pm


Return to Find/Replace/Regular Expressions

cron