Author Topic: Regular Expresssions in Search and Replace  (Read 5480 times)

Offline Wahooney

  • Multiple posting newcomer
  • *
  • Posts: 34
  • Demon Onion Slayer
    • wahooney.net
Regular Expresssions in Search and Replace
« 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.
Fabricati Diem, Celerata!

Offline dje

  • Lives here!
  • ****
  • Posts: 683
Re: Regular Expresssions in Search and Replace
« Reply #1 on: April 08, 2007, 07:28:23 pm »
Hi !

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

Dje

Offline Wahooney

  • Multiple posting newcomer
  • *
  • Posts: 34
  • Demon Onion Slayer
    • wahooney.net
Re: Regular Expresssions in Search and Replace
« Reply #2 on: April 08, 2007, 07:53:43 pm »
I tried that, but it seems the the problem is with ().
Fabricati Diem, Celerata!

Offline dje

  • Lives here!
  • ****
  • Posts: 683
Re: Regular Expresssions in Search and Replace
« Reply #3 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

Offline dmoore

  • Developer
  • Lives here!
  • *****
  • Posts: 1576
Re: Regular Expresssions in Search and Replace
« Reply #4 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

Offline Wahooney

  • Multiple posting newcomer
  • *
  • Posts: 34
  • Demon Onion Slayer
    • wahooney.net
Re: Regular Expresssions in Search and Replace
« Reply #5 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.
Fabricati Diem, Celerata!