This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 228093 - Regular expressions broken in find/replace
Summary: Regular expressions broken in find/replace
Status: RESOLVED FIXED
Alias: None
Product: utilities
Classification: Unclassified
Component: Search (show other bugs)
Version: 7.3
Hardware: PC Windows 7 x64
: P2 normal (vote)
Assignee: Jaroslav Havlin
URL:
Keywords:
: 239247 (view as bug list)
Depends on:
Blocks:
 
Reported: 2013-03-29 16:33 UTC by gnomed
Modified: 2013-12-09 08:56 UTC (History)
3 users (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description gnomed 2013-03-29 16:33:16 UTC
Encountered a couple issues using the find/replace dialog (started using shift + ctrl + H).

Most important, is it does not work with regular expressions. I entered a regular expression of ";\n" (which is hardly a regex, but it also fails with ";$"). Using the "test" dialog, I entered test text of:

test;
test;
test;

Entering ";\n" would match the first 2 semicolons, as expected. ";$" would match the last semicolon as expected (although in some editors this would match all semicolons, i.e. KomodoEdit).

I click "Apply" in the test dialog to return to the "Replace in Projects" dialog where it fills in the regular expression I was just testing. 

I click "Find" (which was a bit of a trip when I was expecting a "replace" button), and it returns no results (and trust me, there are definitely a number of lines that end in a semicolon followed by a newline, I also pasted the testing text into the file as well). I also tested with ";\r\n" and ";\r".

Somewhat related, but there is also no easy way to only find/replace within selected text (again common in many editors). I think there is a way somewhere, but it must not be intuitive. I did it once successfully using the quick replace toolbar somehow, but I see no explicit option on it. Similarly there is apparently no explicit option in the "Replace in Project" dialog. I would have expected it to be the "Selection" option in the "scope" dropdown, but this seems to consistently just search the entire currently focused file (regardless of highlighted selection).

Finally, doing a find/replace does not add to the undo/redo stack, so I cannot undo a find/replace. Which was particularly unfortunate when I accidentally did a find/replace on the entire file because it did not apply to my highlighted selection as expected. Which is now proving hard to correct because I cannot match newlines... Talk about a series of unfortunate events.

Let me know if you would like me to split these last 2 issues into separate bug reports. Also let me know if there is any other information I can provide.
Comment 1 Jaroslav Havlin 2013-04-04 09:25:42 UTC
(In reply to comment #0)
> Most important, is it does not work with regular expressions. [...]
> I click "Find" (which was a bit of a trip when I was expecting a "replace"
> button), and it returns no results (and trust me, there are definitely 
> a number of lines that end in a semicolon followed by a newline, I also
> pasted the testing text into the file as well). I also tested with ";\r\n" 
> and ";\r".
Pattern ";\n" doesn't work for me as well in Search (Replace) in Projects, but patterns ";\r\n" and ";$" work well.

It seems that the regular expression mode is not used by the algorithm. Did you try to restart the IDE? (I guess you did.)

> Somewhat related, but there is also no easy way to only find/replace within
> selected text (again common in many editors). I think there is a way 
> somewhere, but it must not be intuitive. I did it once successfully using the 
> quick replace toolbar somehow, but I see no explicit option on it.
You need to use Find/Replace in the editor (Ctrl+F, or Ctrl+H) when some text is selected. Also see bug 207532.

> Similarly there is apparently no explicit option in the "Replace in Project" 
> dialog. I would have expected it to be the "Selection" option in the "scope" 
> dropdown, but this seems to consistently just search the entire currently 
> focused file (regardless of highlighted selection).
Search in projects is not designed to support selections in editor. The scope "Selection" can be used to search in files selected e.g. in Projects window.
(Try to select some files in Projects window and press Ctrl+F, scope "Selection" will be selected by default.)

> Finally, doing a find/replace does not add to the undo/redo stack, so I cannot
> undo a find/replace. Which was particularly unfortunate when I accidentally 
> did a find/replace on the entire file because it did not apply to my 
> highlighted selection as expected. Which is now proving hard to correct 
> because I cannot match newlines... Talk about a series of unfortunate
> events.
Already reported in bug 223019.
Did you try use local file "History"? (Button in the editor toolbar, next to "Source".) It's also always safer to use some version control system.

> Let me know if you would like me to split these last 2 issues into 
> separate bug reports. Also let me know if there is any other information 
> I can provide.
It's always better to split bug reports, but the bugs are already reported, no problem in this case.

Thank you.
Comment 2 Jaroslav Havlin 2013-06-13 14:10:05 UTC
http://hg.netbeans.org/core-main/rev/e4b4570e747b
Fixed. Now you can select which newline sequence you want to use in the "test" dialog (system default is preselected).

> ";$" would match the last semicolon as expected (although in some editors 
> this would match all semicolons, i.e. KomodoEdit).
Now it also matches all semicolons, as it will work so in the real search.

Thank you for reporting.
Comment 3 Quality Engineering 2013-06-15 03:04:57 UTC
Integrated into 'main-golden', will be available in build *201306142301* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)
Changeset: http://hg.netbeans.org/main-golden/rev/e4b4570e747b
User: Jaroslav Havlin <jhavlin@netbeans.org>
Log: #228093: Better support for various new-line sequences in dialog for testing regexps
Comment 4 Jaroslav Havlin 2013-12-09 08:56:15 UTC
*** Bug 239247 has been marked as a duplicate of this bug. ***