Regular Expressions 101

Sponsors

Community Patterns

Community Library Entry

1

Regular Expression
Created·2016-07-01 23:43
Flavor·PCRE (Legacy)

/
(^[\r\n]*|[\r\n]+)[\s\t]*[\r\n]+
/
g
Open regex in editor

Description

Removes all blank lines.

PHP: trim(preg_replace("/(^[\r\n]|[\r\n]+)[\s\t][\r\n]+/", "\n", $string));

You have replace with a newline char to break non-blank lines. This also leaves a single trailing newline, easily removed with trim($string); if needed.

Submitted by anonymous