繁体   English   中英

正则表达式在记事本++之间替换

[英]Regex replace between notepad++

我在 csv 中有一个值列表,我试图使用 REGEX 搜索稍微改变它并使用 Notepad++ 替换。 我所拥有的包含以下示例:

Text,UK_BT.BT1.BT1 1,123
Text,UK_BT.BT11.BT11 1,123
Text,IE_text.text.text,123

我想要做的是删除第一个逗号和最后一个句点之间的文本,在该行包含 UK_BT 的地方。 所以输出将是:

Text,BT1 1,123
Text,BT11 1,123
Text,IE_text.text.text,123

有没有人有任何线索? 正则表达式真的不是我的强项,使用后通常会被遗忘! 谢谢,

找到什么: ^(?=.*UK_BT.*)([^,]+,).*\\.([^\\.]+)$

替换为\\1\\2

说明

^             # Beginning of the line.
(?=.*UK_BT.*) # Must contain 'UK_BT' (positive look ahead, not capturing group, not character consuming).
(             # Beginning of the first group.
  [^,]+,      # Everything but ',' at least one time (+) followed by ',' (first ',').
)             # End of the first group.
.*            # Everything zero or more times.
\.            # A single '.'.
(             # Beginning of the second group.
 [^\.]+       # Everything but '.' at least one time (this in combination with '\.' allows to find the last '.').
)             # End of the second group.
$             # End of the line

\\1\\2允许指向第一个和第二个捕获的组。

下次试试吧,下次不会忘记的。。。
查找内容: UK.+\\d\\.
替换为: nothing

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM