Code::Blocks Forums

User forums => Using Code::Blocks => Topic started by: Wahooney on April 08, 2007, 02:00:51 pm

Title: Regular Expresssions in Search and Replace
Post by: Wahooney on April 08, 2007, 02:00:51 pm
Can anyone point me to a reference sheet for regular expressions in the search and replace in Code::Blocks?

Certain expressions don't work that I'm familiar with, eg. if I search for (thing) and replace it with my_\1 I expect thing to be replaced with my_thing, which I don't get, S&R just closes as if there is nothing to find or replace.

Thanks guys.
Title: Re: Regular Expresssions in Search and Replace
Post by: dje on April 08, 2007, 07:28:23 pm
Hi !

Did you try $1 instead of \1 in your replacement pattern ?

Dje
Title: Re: Regular Expresssions in Search and Replace
Post by: Wahooney on April 08, 2007, 07:53:43 pm
I tried that, but it seems the the problem is with ().
Title: Re: Regular Expresssions in Search and Replace
Post by: dje on April 08, 2007, 09:03:34 pm
Little tricky but I found the solution.
Just put \ before parenthesis (or reg exp special chars).

For example, to replace class name in :
Code
class foo : public bar
{
}

Put in search :
Code
class \([a-zA-Z0-9_]+\) :

and in replace:
Code
class my_\1 :

It works ! :D

Dje
Title: Re: Regular Expresssions in Search and Replace
Post by: dmoore on April 19, 2007, 03:07:09 pm
I tried that, but it seems the the problem is with ().

if you are using a nightly from this year you can switch on POSIX style regexes in editor settings, which uses (group) to enclose groups instead of \(group\)

if you are using a nightly from last week or more recent you can switch on advanced regex find and replace in editor settings and get even more advanced syntax: http://www.wxwidgets.org/manuals/stable/wx_wxresyn.html#wxresyn
Title: Re: Regular Expresssions in Search and Replace
Post by: Wahooney on April 19, 2007, 04:08:01 pm
I solved this a week ago, I should have let everyone know :oops:, thanks for all the help guys.