正则表达式:在行首添加连字符破折号,其中不存在连字符破折号

正则表达式:在行首添加连字符破折号,其中不存在连字符破折号

下午好。我想在行首添加连字符(破折号),而行首没有连字符破折号。例如,我有以下文本:

I love books.
I want some money.
I need help.
- I want to ask you something.
- I want to love you.
I need hits.
- I get done with this.

输出应该是:

- I love books.
- I want some money.
- I need help.
- I want to ask you something.
- I want to love you.
- I need hits.
- I get done with this.

答案1

在行首没有连字符的地方添加连字符。

寻找:^(?!-)

替换为:-\x20

或者

寻找:^(?!-)(?:\r?|\r)

替换为:-\x20

如果您只想在空白行处添加连字符(破折号):

寻找:^(?!-)\s*\r

替换为:-\x20

或者

寻找:^(?!-)(?!\w+)

替换为:-\x20

相关内容