使用RegEx搜索和替换用一条空白行替换多条空白行

编程入门 行业动态 更新时间:2024-10-28 08:27:26
本文介绍了使用RegEx搜索和替换用一条空白行替换多条空白行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个文件需要重新格式化并删除多余的"空白行.

I have a file that I need to reformat and remove "extra" blank lines.

我正在使用Perl语法正则表达式搜索并替换UltraEdit的功能,并且需要将正则表达式放入查找内容:"字段中.

I am using the Perl syntax regular expression search and replace functionality of UltraEdit and need the regular expression to put in the "Find What:" field.

这是我需要重新格式化的文件示例.

Here is a sample of the file I need to re-format.

All current text REPLACE with all the following: Winter 2011 Class Schedule Winter 2011 Class Registration Dates: Dec. 6, 2010 – Jan. 1, 2011 Winter 2011 Class Session Dates: Jan. 5 – Feb. 12, 2011 DANCE Adventures in Ballet & Tap 3 – 6 years Instructor: Ann Newby Tots ages 3 – 6 years old develop a greater sense of rhythm, flexibility and coordination as they explore the basic elements of movement. Saturdays 9 - 10 a.m. Jan. 8 – Feb. 12 Six-week fees: $30 African Storytelling 3 – 6 years Instructor: Ann Newby Tots ages 3 – 6 years old explore storytelling and fables through spoken word, music, movement and visual arts experiences. Saturdays 10 – 11 a.m. Jan. 8 – Feb. 12 Six-week fee: $30 African Dance / Children

您会注意到,某些双空行中有空格或制表符,或两者都有.

You'll notice that some of the double blank lines have spaces or tabs or both in them.

运行搜索和替换后,我应该拥有一个看起来像这样的文件.

After the search and replace has been run I should have a file that looks like this.

All current text REPLACE with all the following: Winter 2011 Class Schedule Winter 2011 Class Registration Dates: Dec. 6, 2010 – Jan. 1, 2011 Winter 2011 Class Session Dates: Jan. 5 – Feb. 12, 2011 DANCE Adventures in Ballet & Tap 3 – 6 years Instructor: Ann Newby Tots ages 3 – 6 years old develop a greater sense of rhythm, flexibility and coordination as they explore the basic elements of movement. Saturdays 9 - 10 a.m. Jan. 8 – Feb. 12 Six-week fees: $30 African Storytelling 3 – 6 years Instructor: Ann Newby Tots ages 3 – 6 years old explore storytelling and fables through spoken word, music, movement and visual arts experiences. Saturdays 10 – 11 a.m. Jan. 8 – Feb. 12 Six-week fee: $30 African Dance / Children

推荐答案

替换

^(\s*\r\n){2,}

使用

\r\n

这就是我最终得到的结果.

Is what I ended up with.

这只会选择两个或多个倍数的空行,并将其替换为一个.

This only selects blank lines in multiples of two or more and replaces them with one.

更多推荐

使用RegEx搜索和替换用一条空白行替换多条空白行

本文发布于:2023-06-03 08:56:55,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/470182.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:空白   多条   RegEx

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!