正则表达式修改以关键短语开头的行后面的行?

时间:2010-03-02 05:22:42

标签: regex

我有一个巨大的文件,有一些行需要在它们下面有一行破折号,然后是一个空行。

所有这些行都以相同的特定单词模式( "Dollars required for" )开头,但该行上的每个其他单词都不同于一行到下一行。

例如,该文件目前看起来像这样:

Dollars required for: "International Exchange"
Some other text on the next line
...
Dollars required for: "Trade Operations"
(blank line)
Some other text on the next line

但它需要看起来像这样:

Dollars required for: "International Exchange"
---------------------------------------------- (inserted line of dashes)
                                               (inserted blank line)
Some other text on the next line
...
Dollars required for: "Trade Operations"
---------------------------------------------- (inserted line of dashes)
                                               (inserted blank line)
(blank line)
Some other text on the next line

我可以在文本编辑器(Jedit)的查找/替换功能中使用正则表达式来执行此修改吗?

2 个答案:

答案 0 :(得分:1)

查找

Dollars required for: (.*)$

替换为:

Dollars required for: $1\n----------------------------------------------\n

(假设find / replace支持换行的转义,等等。)

答案 1 :(得分:1)

搜索:

 ^(Dollars required for: .*)$

替换为:

 $1\n----------------------------------------------\n\n

Jedit可以做到IRC。