News:

Accounts with zero posts and zero activity during the last months will be deleted periodically to fight SPAM!

Main Menu

replace and reg ex

Started by mitsukai, May 10, 2007, 09:29:31 PM

Previous topic - Next topic

mitsukai

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

dmoore

#1
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
Python plugins: [url="https://github.com/spillz/codeblocks-python"]https://github.com/spillz/codeblocks-python[/url]
Code::Blocks Daily Builds -- Ubuntu PPA: [url="https://launchpad.net/~damien-moore/+archive/codeblocks"]https://launchpad.net/~damien-moore/+archive/codeblocks[/url]

mitsukai

#2
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

dmoore

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.
Python plugins: [url="https://github.com/spillz/codeblocks-python"]https://github.com/spillz/codeblocks-python[/url]
Code::Blocks Daily Builds -- Ubuntu PPA: [url="https://launchpad.net/~damien-moore/+archive/codeblocks"]https://launchpad.net/~damien-moore/+archive/codeblocks[/url]