Advanced search and replace using notepad++
September 10, 2010 8:24 AM   Subscribe

Help me search and replace all instances of a word that are not preceded by another specific word.

I need to search through several files and replace all instances of 'int8' that are not preceded by 'unsigned ' with 'unsigned int8'.

I know this is possible using notepad++ (and I'd prefer to use this) but I'm not quite sure how to tackle it - regex? a plug-in?

Any help would be really appreciated!
posted by oliverst to Computers & Internet (8 answers total) 3 users marked this as a favorite
 
Search for "unsigned int8"- replace with unused phrase such as "XXX"
Search for "int8" - replace with desired phrase
Search for "XXX" - replace with "unsigned int8"
posted by sharkfu at 8:29 AM on September 10, 2010


The work around if you only have the standard search & replace (e.g. iun Notepad or Word or whatever) would be:

First do a search & replace on "unsigned int8", changing it to (e.g.) "unsigned i--n--t--8". This must change the phrase to something that already exists nowhere else in the document.

Then do a search & replace on changing "int8" to "unsigned int8".
Then do a search & replace on changing "unsigned i--n--t--8" back to "unsigned int8".
posted by EndsOfInvention at 8:30 AM on September 10, 2010


I don't know notepad++, but could you search and replace "int8" with "unsigned int8", then on a second pass, replace any "unsigned unsigned" doubles with a single "unsigned"?
posted by midwestguy at 8:30 AM on September 10, 2010


Do it in two steps:

1. Replace all instances of "int8" with "unsigned int8"
2. Replace all remaining instances with "unsigned unsigned" with "unsigned"
posted by carmicha at 8:31 AM on September 10, 2010 [3 favorites]


I don't know notepad++, but could you search and replace "int8" with "unsigned int8", then on a second pass, replace any "unsigned unsigned" doubles with a single "unsigned"?

Of course! That is 33% quicker than my original method (only uses 2 S&R instead of 3). Only works if "unsigned unsigned int8" isn't already in your file somewhere though.
posted by EndsOfInvention at 8:31 AM on September 10, 2010


Of course! That is 33% quicker than my original method (only uses 2 S&R instead of 3). Only works if "unsigned unsigned int8" isn't already in your file somewhere though.

Just keep searching for 'unsigned unsigned' until it returns zero results.
posted by deezil at 8:37 AM on September 10, 2010


Thanks everyone - not sure why this didn't occur to me immediately... it's been a long day!
posted by oliverst at 8:40 AM on September 10, 2010


It can also be done in a single pass with regexps like this:
s/(unsigned )?int8/unsigned int8/
posted by baf at 8:48 AM on September 10, 2010 [1 favorite]


« Older Does anyone know the approximate Capitol Airshow...   |   How do I stop expecting instability? Newer »
This thread is closed to new comments.