问题
I need to add ; at the end of every line that does not end with :, {, } or ).
I'm using this in Notepad++:
- Search for:
[^:\{\}\)]$ - Replace with:
\1;
It finds the strings all right but it replaces the last character found before the end of line with ; instead of adding it to it. I tried $1 instead of \1 but it didn't change anything — the found text still gets deleted.
回答1:
Your pattern has no capturing group, hence \1 is an empty string. Use $0 instead to refer to the whole match:
Find What: [^:{})]$
Replace with: $0;
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:
Find What: $(?<![:{})])
Replace with: ;
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.
来源:https://stackoverflow.com/questions/51993893/notepad-regex-backreference-doesnt-seem-to-work