Repository: spyder-ide/spyder

Issue:
Regex is not fully functional when using to find&replace
I want to use the following regex
`\["([a-z_]*)"\]`
and want to replace it with 
`.\1`
to change pars["delta_s"] to pars.delta_s or similar. This does work on some lines but not on all. The regular expression is met, but somehow Spyder fails to actual replace the string. More importantly, when clicking Replace/find the cursor does not (always) jump to the next hit but skips one hit. If then replace/find is clicked again it jumps bakc to the one it skipped before



Discussion:
I tested 3 versions of Spyder. from 2.3.8 to the  3.0.0beta 4 
I can very nicely reproduce the bug : 

1) take a file in editor with some lines like : 
aaabbbccc
aaabbbccc
aaabbbccc
aaabbbccc
aaabbbccc

2) make a find&replace with "regexp" activated
search field= a(.*)b
replace field = "ab" (or whatever, this is not changing anything)

3) click on "replace/find"

it find very nicely the next pattern occurence. but does NOT replace it... it just replaces the next occurence. So every 2nd occurence is replaced. And if you click "replace All", it works perfectly (but I got once a freeze for some seconds of Spyder... that's not reproducible.)

I really don't think it is a complicated bug to correct, it just search twice to replace once.

I am also having this issue. The regex identifies the correct lines I want to replace, but it will not modify them in any way.

I am using version 3.0.2
@andfoy, please work on this one. It seems simple to fix :-)

Resolving patch:
diff --git a/spyder/widgets/findreplace.py b/spyder/widgets/findreplace.py
--- a/spyder/widgets/findreplace.py
+++ b/spyder/widgets/findreplace.py
@@ -359,13 +359,22 @@ def replace_find(self):
                     seltxt = to_text_string(self.editor.get_selected_text())
                     cmptxt1 = search_text if case else search_text.lower()
                     cmptxt2 = seltxt if case else seltxt.lower()
-                    if self.editor.has_selected_text() and cmptxt1 == cmptxt2:
-                        # Text was already found, do nothing
-                        pass
+                    if not pattern:
+                        has_selected = self.editor.has_selected_text()
+                        if has_selected and cmptxt1 == cmptxt2:
+                            # Text was already found, do nothing
+                            pass
+                        else:
+                            if not self.find(changed=False, forward=True,
+                                             rehighlight=False):
+                                break
                     else:
-                        if not self.find(changed=False, forward=True,
-                                         rehighlight=False):
-                            break
+                        if len(re.findall(pattern, cmptxt2)) > 0:
+                            pass
+                        else:
+                            if not self.find(changed=False, forward=True,
+                                             rehighlight=False):
+                                break   
                     first = False
                     wrapped = False
                     position = self.editor.get_position('cursor')


Test patch: