Code::Blocks Forums

User forums => General (but related to Code::Blocks) => Topic started by: Poobah on April 05, 2007, 08:43:07 am

Title: Infinite loop in RegEx search & replace
Post by: Poobah on April 05, 2007, 08:43:07 am
If doing a replace search, and you're searching for the end of line and replacing it with something else, it just keeps replacing it, creating a new line after it and then replacing that new line, resulting in an infinite loop if choosing to replace all:

(Make sure to save your work before doing this!)

Text to search for: $
Replace with: ;
Regular expression: True
(Click replace)
(Click all)
Title: Re: Infinite loop in RegEx search & replace
Post by: dje on April 05, 2007, 10:20:32 am
Hi !

Did you try with \r?\n instead of $ (don't know how multiline flag is used) ?

I tried to use reg ex with C::B but the implementation (in scintilla I think) is not complete.
I use external tools to make the reg exp operations.

A great Perl fan.
Title: Re: Infinite loop in RegEx search & replace
Post by: Poobah on April 07, 2007, 07:05:57 am
If I search for either "\r", "\n" or "\r?\n" then it acts as though it hasn't found any occurances of them.
Title: Re: Infinite loop in RegEx search & replace
Post by: dmoore on April 09, 2007, 04:13:53 pm
If doing a replace search, and you're searching for the end of line and replacing it with something else, it just keeps replacing it, creating a new line after it and then replacing that new line, resulting in an infinite loop if choosing to replace all:

(Make sure to save your work before doing this!)

Text to search for: $
Replace with: ;
Regular expression: True
(Click replace)
(Click all)


interesting. this also affects my patched advanced style regex find and replace. I wrote it to allow the user to enable the wxWidgets regex routines instead of the built-in scintilla editor's regex for find and find&replace. I'll take a look at the bug later in the week if noone else beats me to it.

if interested you can see my advanced regex patch here:

https://developer.berlios.de/patch/?func=detailpatch&patch_id=1701&group_id=5358
(I'm surprised none of the developers have looked at it yet...)

and test here using a pre-compiled older revision of CB (windows only):

http://prdownload.berlios.de/cbilplugin/CodeBlocks_unicode_rev3369_with_IL_plugins_Rev1.exe
(you will need to enable advanced style regexes under "Settings" -> "Editor" (under other options)
Title: Re: Infinite loop in RegEx search & replace
Post by: Poobah on April 11, 2007, 04:53:45 am
Does your patch allow usage of subexpressions and all that fancy stuff? I have been wanting to be able to use subexpressions in CB's search and replace.
Title: Re: Infinite loop in RegEx search & replace
Post by: dmoore on April 12, 2007, 02:33:23 pm
Does your patch allow usage of subexpressions and all that fancy stuff? I have been wanting to be able to use subexpressions in CB's search and replace.

you can see exactly what wxWidget's advanced regex is supposed to support here: http://www.wxwidgets.org/manuals/2.8/wx_wxresyn.html

it looks like Mandrav has accepted the patch so you will be able to test this yourself on the latest nightly soon. You will have to enable advanced regex in the editors settings dialog, then it should work for find, replace, find in files and replace in files. there are definitely some issues - for example you will get wierdness if your EOL character is a CR (\r) instead of a LF (\n)

I will look at the infinite loop bug tomorrow.
Title: Re: Infinite loop in RegEx search & replace
Post by: dmoore on April 14, 2007, 05:31:47 pm
bug report (#10886): http://developer.berlios.de/bugs/?func=detailbug&bug_id=10886&group_id=5358

patch (#1960): http://developer.berlios.de/patch/?func=detailpatch&patch_id=1960&group_id=5358

Please test to make sure I have resolved the issue. (I have done some basic testing and have no issues)
Title: Re: Infinite loop in RegEx search & replace
Post by: Poobah on April 15, 2007, 07:43:10 am
How do I use the patch?
Title: Re: Infinite loop in RegEx search & replace
Post by: dmoore on April 15, 2007, 02:48:23 pm
have you compiled CB from source? if you have, you need to download a patch tool (there is a GNU patch tool at http://gnuwin32.sourceforge.net/packages/patch.htm), copy the patch file to the source root then apply it with the appropriate command line. (otherwise you could just modify the source files by hand since there are only 3 changed lines and patch files are quite readable)

otherwise just download and run the pre-compiled barebones win32 CB binary that I have put here: http://www.savefile.com/files/641284 (7-zip archive)

Title: Re: Infinite loop in RegEx search & replace
Post by: Poobah on April 15, 2007, 11:42:16 pm
It seems to work fine for me. Thanks for fixing it!