ant:将双空行替换为单空行

ant:将双空行替换为单空行,ant,replace,Ant,Replace,我试图设置一个脚本,遍历每个文件,并用一个空行替换所有连续的空行。比如: aaa bbb 转化为 aaa bbb 到目前为止,我已经: <replace file="web.xml" value=""> <replacefilter> <replacetoken>\n\n</replacetoken> <replacevalue>\n&l

我试图设置一个脚本,遍历每个文件,并用一个空行替换所有连续的空行。比如:

aaa



bbb
转化为

aaa

bbb
到目前为止,我已经:

<replace file="web.xml" value="">
            <replacefilter>
                <replacetoken>\n\n</replacetoken>
                <replacevalue>\n</replacevalue>
            </replacefilter>
        </replace>

\n\n
\n
但它根本不起作用

到目前为止,唯一的办法是:

<target name="-remove-blank">
        <replaceregexp file="${basedir}/temp/WEB-INF/web.xml"
               match="(\r?\n)\s*\r?\n" 
               flags="g"
               replace="\1" 
        />
    </target>

但这会删除所有空行,而我只需要在有2个或更多连续空行时删除它

 <replaceregexp
  file="some.file"
  match="(${line.separator}){2}"
  replace="${line.separator}"
  flags="g"
 />
和使用:

<replaceregexp
 file="foo.txt"
 match="^(${line.separator}){2,}"
 replace="${line.separator}"
 flags="mg"
/>
作品:

line1

line2

line3

line4

line5

line6
如果行中包含空格,则必须使用:

match="^(\s*${line.separator}){2,}"

line1

line2

line3

line4

line5

line6
match="^(\s*${line.separator}){2,}"
match="^(\s*\r\n){2,}"