Regex to Replace Multiple Blank Lines with One

I'm working on a function to strip HTML, but preserve things like paragraph spacing. In removing HTML tags, sometimes you end up with lots of blank lines... Here's a quick regular expression to convert multiple blank lines with just one \n character:
<cfset content = ReReplace(content, "[\r\n]+", "#Chr(10)#", "ALL")>
Tweet
Related Entries
- Auto-Linking Comments - June 24, 2005
- Widon't and Widows - September 5, 2006
- Textile for ColdFusion - February 13, 2006
- Cheat Sheet Roundup - Over 30 Cheatsheets for developers - September 1, 2005
- REFind and ReReplace support \r \n and \t - March 28, 2005
Trackbacks
Comments
[\r\n]+\t*[\r\n]*
never been good with RegEx, though.
OR
FileReader fr = new FileReader("in.txt"); BufferedReader in = new BufferedReader(fr); FileWriter fw = new FileWriter("out.txt"); BufferedWriter out = new BufferedWriter(fw); String data; while ((data = in.readLine()) != null) { if (data.length() > 0) { out.write(data); out.newLine(); } } in.close(); out.close();
thanks.
for PHP users having difficulty putting this suggestion into practice, use the following.
$string=eregi_replace("[\r\n]+", "\n\n", $string);
job. done.
Post a Comment
Recent Entries
- Writing Secure CFML cfObjective 2013 Slides
- Upgrading to Java 7 on Linux
- J2EE Sessions in CF10 Uses Secure Cookies
- Learn about ColdFusion Security at cfObjective 2013
- Session Loss and Session Fixation in ColdFusion
- FuseGuard 2.3 Released
- CKEditor Spell Checker Plugin
- Adobe Says Go Ahead and Upgrade your ColdFusion JVM


add to del.icio.us



