且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Notepad++ 正则表达式反向引用似乎不起作用

更新时间:2023-02-17 23:14:00

你的模式没有捕获组,因此 \1 是一个空字符串.改用 $0 来引用整个匹配项:

Your pattern has no capturing group, hence \1 is an empty string. Use $0 instead to refer to the whole match:

查找内容:[^:{})]$
替换为:$0;

然而,在某些边缘情况下它可能会失败([^:{})]$ 模式匹配除 :{ 之外的任何字符code>、}),因此在行结束前至少需要 1 个字符),也许,您***在此处使用负向后视:

However, it might fail in some edge cases (the [^:{})]$ pattern matches any char other than :, {, } and ), so requires at least 1 char before a line end), perhaps, you should better use a negative lookbehind here:

查找内容:$(?<![:{})])
替换为:;

$(?<![:{})]) 模式匹配行尾(使用 $),然后是 (?<![:{})]) 负向后视确保没有 :{}>) 紧接在当前位置的左侧.

The $(?<![:{})]) pattern matches the end of line (with $) and then the (?<![:{})]) negative lookbehind makes sure that there is no :, {, } or ) immediately to the left of the current location.