Notepad++ regexp to search and replace with exceptions
I'm a regexp newbie and I would like to know how to do a search and replace for the开发者_运维知识库 following case:
A file contains many occurrences of the following:
L1234_XL3.ext
and also many occurrences of:
L1234_XL3
I only want to find and replace L1234_XL3
occurrences with XL3
without affecting instances that have an extension.
I am using notepad++ to do the regular expression.
If Notepad++ supports lookaheads, you can simply use L1234_XL3(?!\.ext)
for the search and "XL3" for the replacement.
EDIT: Looks like it doesn't support lookaheads after all. A pity; you'll have to do it the hard way without regexes (regexen?):
- Replace L1234_XL3.ext with QQQ (or any other string that doesn't appear in the file)
- Replace L1234_XL3 with XL3.
- Replace QQQ with L1234_XL3.ext.
Step 1. Change all occurences of L1234_XL3.ext to L-1-2-3-4_XL3.ext (for example)
Step 2. Change all occurences of L1234_XL3 to XL3
Step 3. Change all occurences of L-1-2-3-4_XL3.ext back to L1234_XL3.ext
As far as I understand Notepad++ 5.4.5 doesn't support positive lookahead
精彩评论