Code::Blocks Forums
User forums => Using Code::Blocks => Topic started by: rickg22 on July 05, 2007, 09:19:02 pm
-
I've been trying to replace some strings in CB using regular expressions, but i can't get it to work. Can you provide me some examples?
Also, how do the "advanced regular expressions" and "use POSIX-style..." options alter the regex search?
Please help! :(
Thanks :)
-
that's hard to explain just by forum, pff, tell us one you want to have, if it i not to complicated we can give the answer and explain that one ?
-
..are you aware of the regexp testbed plugin in C::B?
This is helpful for testing at least...
-
Also, how do the "advanced regular expressions" and "use POSIX-style..." options alter the regex search?
blame me for that :)
* With both options unchecked, you get the default regex engine built into scintilla (a pretty weak implementation IMO). Regex "groups" are enclosed in escaped parantheses \( and \). this is helpful when you want to search for text that actually contains "(" or ")" characters and don't use groups very often (e.g. when working with LISP code).
* with POSIX checked (but advanced unchecked), regex groups are enclosed in ( and ), and to find the literal "(" and ")" chars you need to escape them \( \)
* Checking advanced regular expressions overrides scintilla RE and you get wxWidgets more powerful ARE syntax (link in my sig). The POSIX checkbox is irrelevant (I don't think AREs offer the choice of escaped vs unescaped parentheses). So, ideally when advanced is check, POSIX-style should just be greyed out.
The tradeoff between the scinitlla RE and wxWidgets is naturally a choice between a speedy native implementation in scintilla vs a powerful but slower ARE implementation (slower mostly because of the way I implemented the find and replace code).
As a side note: The ARE engine used by wxWidgets was written by Henry Spencer and distributed under a virtually unrestricted license other than the need to give him credit (and note any alterations to the code). Bizarrely, this was a sufficient disincentive for the Scintilla guy(s) to natively include AREs. It's hard to tell whether that was out of ignorance or arrogance...
-
Thanks! I managed to use the regexes now :)
-
that's hard to explain just by forum, pff, tell us one you want to have, if it i not to complicated we can give the answer and explain that one ?
my situation:
i want to replace
by
i managed to find (if|switch|for|while) \((.*?)\)
but i cannot imagine what token C::B uses for replacement
it's neither
$1 ( $2 )
nor
%1 ( $2 )
not even
\\1 ( \\2 )
what is a replacement template here?
-
may be you will consult me how to do it from linux command line? all *.c files at once
thanks in advance