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
- Nginx redirect www to non www domain
- HashDOS and ColdFusion
- HackMyCF Updated for APSB11-29 Security Hotfix
- Adobe eSeminar on FuseGuard
- Determining Which Cumulative Hotfixes are Installed on ColdFusion
- Adding Two Factor Authentication to ColdFusion Administrator
- ColdFusion Developer Week at Adobe.com
- Bug Loading Scripts for CFFileUpload and CFMediaPlayer


add to del.icio.us



