views:

422

answers:

2

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.

+2  A: 

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?):

  1. Replace L1234_XL3.ext with QQQ (or any other string that doesn't appear in the file)
  2. Replace L1234_XL3 with XL3.
  3. Replace QQQ with L1234_XL3.ext.
Max Shawabkeh
just tried it - doesn't seem to support lookaheads
Seth
+2  A: 

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

skwllsp
yeah thought of this already, but I thought it would be nice to know the regexp.
Seth
You can find out about positive lookahead here : http://www.regular-expressions.info/lookaround.html. Although to use it you need an other editor. Personally I use EditPadPro
skwllsp