How to use regular expressions in XCode Find/Replace

  • Folks,

    I'm trying to use the File specific find/replace feature to replace
    some text using Regex.  Now, I'm now regex expert, but I'm trying to
    do something which works in another IDE.  Basically, I'm trying to
    transform a bunch of code that looks like:

    @synthesize UIView *aView;

    into

    @synthesize aView = _aView;

    My regex find is

    \@synthesize\ .*\*(.*)\;

    My replacement is:

    @synthesize $1 = _$1\;

    Either I'm doing something wrong or XCode doesn't recognize the $1
    replacement parameter, because I end up with @synthesize $1 = _$1;
    Note that I copied and pasted this code into my other IDE and ran the
    same Regex find/replace, and it did what I wanted.  That certainly
    doesn't mean XCode does it the same way, but I would appreciate any
    advice on how to get this to work, because I use this feature quite a
    lot.

    Regards,
    Paul
  • On 11 Aug 2009, at 11:51 AM, Paul Summermatter wrote:

    > Either I'm doing something wrong or XCode doesn't recognize the $1
    > replacement parameter, because I end up with @synthesize $1 = _$1;

    It doesn't. Use \1 instead.

    — F

    --
    Fritz Anderson -- Xcode 3 Unleashed: Now in its second printing -- <http://x3u.manoverboard.org/>
  • Fritz et al,

    Thanks very much for the tip.  This will help me a lot.

    Along similar lines, other IDEs have this concept of Find and Replace
    with a Preserve Case option.  Let me explain with an example.  Let's
    say I have code like:

    static NSString *BUYER_DEFAULT_NAME;
    NSString *buyerName;

    I can do a preserve case find/replace and change buyer to seller,
    such that I end up with:

    static NSString *SELLER_DEFAULT_NAME;
    NSString *sellerName;

    Can the same thing be done in XCode?  If so, I haven't been able to
    find it/figure it out.

    Regards,
    Paul

    On Aug 11, 2009, at 1:47 PM, Fritz Anderson wrote:

    > On 11 Aug 2009, at 11:51 AM, Paul Summermatter wrote:
    >
    >> Either I'm doing something wrong or XCode doesn't recognize the $1
    >> replacement parameter, because I end up with @synthesize $1 = _$1;
    >
    > It doesn't. Use \1 instead.
    >
    > — F
    >
    > --
    > Fritz Anderson -- Xcode 3 Unleashed: Now in its second printing -- <http://x3u.manoverboard.org/
    > >
    >
previous month august 2009 next month
MTWTFSS
          1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31            
Go to today