Author Topic: replace and reg ex  (Read 3096 times)

mitsukai

  • Guest
replace and reg ex
« on: May 10, 2007, 09:29:31 pm »
hi

i wanted to replace all 'return(.*)' with 'return .*'
but this dint seem to work. how do i put the .* back in the replacement??
i could use code style plugin but this is alot of work to put my coding style.. and might not work as i want..

Offline dmoore

  • Developer
  • Lives here!
  • *****
  • Posts: 1576
Re: replace and reg ex
« Reply #1 on: May 10, 2007, 09:57:10 pm »
I'm assuming you've switched on Advanced regexes in editor settings...

you define replacement groups by enclosing them in () and you refer to found groups using their numbered position in the replacement using \1, \2, \3 etc.
to search for "(" or ")" characters (and most other punctuation) you need to escape them with a prefixed "\"

so your search string should be: return \((.*)\)
so your replace string should be: return \1

the link to the wxwidgets regex syntax documentation is in my sig
« Last Edit: May 10, 2007, 10:00:36 pm by dmoore »

mitsukai

  • Guest
Re: replace and reg ex
« Reply #2 on: May 10, 2007, 10:12:15 pm »
thank you alot..
this really helps me :)

this doesnt work as u are saying it is.
it does not seem to parses enclosure groups as u are saying it is
\1 seems to parse with (blah)...

ok got it..

it should be:
so your search string should be: return(\(.*\))
so your replace string should be: return \1
« Last Edit: May 10, 2007, 10:20:17 pm by mitsukai »

Offline dmoore

  • Developer
  • Lives here!
  • *****
  • Posts: 1576
Re: replace and reg ex
« Reply #3 on: May 10, 2007, 10:25:29 pm »
that's because you don't have advanced regexes enabled. the groups are defined using \( and \) in the standard regex library (the one activated in code::blocks by default).

you have to switch on the advanced regex library in editor settings for the groups to be defined with ( and ). the advanced library offers much more flexible regex syntax overall.