从csv行中删除包含特定单词的特定单词

时间:2015-04-16 21:03:17

标签: regex csv notepad++

我在csv文件中导出了元关键字

前:

For Rent ABC-1234 , For Rent ABC-1234 Rental, For Rent ABC1234 , For Rent ABC1234 Rental, For Rent ABC 1234 , For Rent ABC 1234 Rental, For Lease ABC-1234 , For Lease ABC-1234 Rental, For Lease ABC1234 , For Lease ABC1234 Rental, For Lease ABC 1234 , For Lease ABC 1234 Rental

我想要做的是读取" For Rent XXX Rental"删除" For Rent"从这些值中,剩下的值只会读取" XXX Rental"。

这可以用正则表达式吗?

2 个答案:

答案 0 :(得分:2)

您可以在查找内容字段中使用此正则表达式:

For Rent ([^,]+ Rental)

替换为

$1

[^,]表示"任何字符,但逗号,+ - 1次或更多次。我看到值是逗号分隔的,所以这似乎是一个安全的模式。为了更安全的匹配,您可以在查找内容字段中尝试For Rent ([^,]*? +Rental)(这也会占用Rental之前的多个空格)。

输出:

For Rent ABC-1234 , ABC-1234 Rental, For Rent ABC1234 , ABC1234 Rental, For Rent ABC 1234 , ABC 1234 Rental, For Lease ABC-1234 , For Lease ABC-1234 Rental, For Lease ABC1234 , For Lease ABC1234 Rental, For Lease ABC 1234 , For Lease ABC 1234 Rental

enter image description here

答案 1 :(得分:0)

我认为这就是你想要的:

(A[^,]+\d Rental)

这将从“出租/租赁xxx租赁”中选择“xxx租赁”,您无需更换任何东西。

编辑:

如果i(不区分大小写)标志未打开,则上述方法有效。

对于不区分大小写的正则表达式,请改用以下代码:

(?<=\w{4}\s|\w{5}\s)([^,]+\d Rental)
  • (?<=\w{4}\s|\w{5}\s)正面看模式,匹配字符串后跟\w{4}\s(租金)或\w{5}\s(租赁)。

For \w+ \K([^,]+\d Rental)
  • \K会丢弃之前的所有比赛并从当前位置开始匹配。
相关问题