User forums > Using Code::Blocks

Regular Expresssions in Search and Replace

(1/2) > >>

Wahooney:
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.

dje:
Hi !

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

Dje

Wahooney:
I tried that, but it seems the the problem is with ().

dje:
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
{
}
--- End code ---

Put in search :

--- Code: ---class \([a-zA-Z0-9_]+\) :
--- End code ---

and in replace:

--- Code: ---class my_\1 :
--- End code ---

It works ! :D

Dje

dmoore:

--- Quote from: Wahooney on April 08, 2007, 07:53:43 pm ---I tried that, but it seems the the problem is with ().

--- End quote ---

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

Navigation

[0] Message Index

[#] Next page

Go to full version