gpt4 book ai didi

regex - 寻找带有正则表达式的字符串并删除整行

转载 作者:行者123 更新时间:2023-12-02 04:46:03 25 4
gpt4 key购买 nike

我试图在 Textpad 中找到一个带有正则表达式的字符(例如“#”),如果找到它,则应删除整行。 # 既不在行首也不在末尾,而是介于两者之间,并且不与另一个单词、数字或字符相连——它单独存在,左右各有一个空格,但当然,该行的其余部分包含单词和数。

例子:

My first line
My second line with # hash
My third line# with hash

结果:

My first line
My third line# with hash

我怎样才能做到这一点?

最佳答案

让我们分解一下:

^     # Start of line
.* # any number of characters (except newline)
[ \t] # whitespace (tab or space)
\# # hashmark
[ \t] # whitespace (tab or space)
.* # any number of characters (except newline)

或者,在一行中:^.*[\t]#[\t].*

关于regex - 寻找带有正则表达式的字符串并删除整行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19790199/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com