Regular Expression Search And Replace in Xcode
I'm attempting to do some massive search and replaces in Xcode, but it's not working out. My search is #include <\S+> and I want to replace the <> with "". I've tried #include "\1" as the replacement text but then I just get #include "" in my file. I tried doing #include "\0" as the replace but then I just get the whole line that search found inside the quotes. How can I just get the file out of the search to replace the <>'s with ""'s?
you cant put any regex in the replace field, use sed instead.
Sir, e^iπ + 1 = 0, hence God exists; reply!
Thanks for the tip. I've written a small script that does this pretty well:
Is there any way to make it so that I can just pass all header files and .cpp files to the script and have it work? It currently doesn't seem to like me trying this:
But the script works perfect if I just call ./ReplaceIncludes test.h. Any ideas?
Code:
#!/bin/sh
sed 's_#include <\([a-z,A-Z,\/]*\).h>_#include "\1.h"_' $1 > .temp
rm $1
cp .temp $1
rm .tempIs there any way to make it so that I can just pass all header files and .cpp files to the script and have it work? It currently doesn't seem to like me trying this:
Code:
~/Desktop > ./ReplaceIncludes *.h
sed: test: No such file or directory
sed: copy: No such file or directory
sed: 1.h.h: No such file or directory
rm: test: No such file or directory
rm: copy: No such file or directory
rm: 1.h.h: No such file or directoryBut the script works perfect if I just call ./ReplaceIncludes test.h. Any ideas?
You can use regular expressions in TextWrangler (free), and do a search & replace on multiple files/folders.
unknown Wrote:you cant put any regex in the replace field, use sed instead.
After playing with sed and reading more about the regular expressions, I can in fact accomplish this in Xcode. For the search I used to just have:
#include <\S+>
and replace with
#include "\1">
but all I got was
#include "".
To fix this I changed the search to using parenthesis like this:
#include <(\S+)>
and then it worked perfectly.
Possibly Related Threads...
| Thread: | Author | Replies: | Views: | Last Post | |
| framework search path | scarypajamas | 0 | 2,823 |
Dec 23, 2008 01:50 PM Last Post: scarypajamas |
|
| Xcode and library search paths | WhatMeWorry | 4 | 5,899 |
Dec 11, 2006 04:09 PM Last Post: WhatMeWorry |
|

