User forums > Using Code::Blocks
How do regular expressions work?
rickg22:
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 :)
killerbot:
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 ?
MortenMacFly:
..are you aware of the regexp testbed plugin in C::B?
This is helpful for testing at least...
dmoore:
--- Quote from: rickg22 on July 05, 2007, 09:19:02 pm ---Also, how do the "advanced regular expressions" and "use POSIX-style..." options alter the regex search?
--- End quote ---
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...
rickg22:
Thanks! I managed to use the regexes now :)
Navigation
[0] Message Index
[#] Next page
Go to full version