空行和正则表达式仅包含一个字符

时间:2016-02-10 09:59:46

标签: c# regex

我正在搜索用于替换C#的正则表达式的模式,这将删除txt文件中的所有空行以及只有一个字符的行,即' *'。这个角色有领先的TAB。

帮助我使用正确的模式从下面的文本中删除这些行:

Bla bla bla 


Bla bla bla
                  *
Bla bla bla
Bla bla bla

期望:

Bla bla bla 
Bla bla bla
Bla bla bla
Bla bla bla

1 个答案:

答案 0 :(得分:0)

除了我的评论,您还可以使用以下正则表达式:

^\s*\*?$\R
# look for whitespaces at the beginning of the line/string
# look for the star literally right at the end
# match a newline character
# anchor the expression to the beginning and end

在多线模式下,您需要用空字符串替换所有出现的内容,请参阅a demo on regex101.com

相关问题