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 148989

Summary: [65cat] Allow linebreaks, tabs for Find/Replace actions
Product: editor Reporter: ulfzibis <ulfzibis>
Component: SearchAssignee: Milutin Kristofic <mkristofic>
Status: NEW ---    
Severity: blocker CC: BritishV8, egemenk, headbank, lanthale, localhorst, malfunction84, markiewb, pjiricka, popov130, SebastianZ, swiftless
Priority: P3 Keywords: PLAN
Version: 6.x   
Hardware: All   
OS: All   
Issue Type: ENHANCEMENT Exception Reporter:

Description ulfzibis 2008-10-02 16:46:20 UTC
[ BUILD # : 200809220201 ]
[ JDK VERSION : 1.6.0_07 ]

Assume, you want find:
"+
    "
, and maybe replace it by nothing,
or find white-spaces or braces at line-end.

These simple actions IMHO should be possible, by marking the search
pattern by mouse, and search by Ctrl-F.

Also the replace string in Replace action should work, if mouse
selected pattern contains tabs or line-ends.

Most other editors have this, e.g. Notepad++.
Comment 1 Andrey Yamkovoy 2009-01-28 14:29:32 UTC
In description you are talking about editor search. So reassign to the editor for evaluation.
As for the "Find In Project" functionality you can find line breaks by using '\r' and '\n' in the regexp. The same for
the replace ...
Comment 2 ulfzibis 2009-01-28 17:49:07 UTC
Yes, the regex way is a kind of workaround here, but ...
1. it must be learned, nothing for beginners, of if you are in a hurry. wildcard's are much more complicated than just
using '*'.
2. I'm more thinking about a cut-'n-paste usage for find AND replace.

What about of transforming the cut string to a valid regex-string on pasting it into the Find/Replace dialogue?
Comment 3 ulfzibis 2010-09-23 11:15:54 UTC
(In reply to comment #2)
> What about of transforming the cut string to a valid regex-string on pasting it
> into the Find/Replace dialogue?

Another interesting idea.
This would slightly teach users in regex over the time, a little!

But please have a look on combined find/replace dialogue of NotePad++, and how they deal with \n \t etc..
This is my favourite from all editors.

I think, we don't need 2 separate dialogues and actions for find and replace, but better availability in any context e.g. bug 187174 148984 146810.
Comment 4 David Strupl 2011-01-13 10:04:55 UTC
*** Bug 194292 has been marked as a duplicate of this bug. ***
Comment 5 David Strupl 2011-01-13 10:05:28 UTC
*** Bug 189029 has been marked as a duplicate of this bug. ***
Comment 6 David Strupl 2011-01-13 10:06:07 UTC
*** Bug 184191 has been marked as a duplicate of this bug. ***
Comment 7 David Strupl 2011-01-13 10:06:51 UTC
*** Bug 158046 has been marked as a duplicate of this bug. ***
Comment 8 malfunction84 2011-02-17 16:10:00 UTC
*** Bug 195575 has been marked as a duplicate of this bug. ***
Comment 9 Milutin Kristofic 2012-01-25 12:34:14 UTC
I will change whole infrastructure for search, which will enable multiline search and regexps.

This is a big change and it doesn't have a high priority now. I hope it will be at least in 7.3.
Comment 10 swpalmer 2014-03-15 03:21:18 UTC
Regexp search/replace is working in NB 8.0 FCS build.  I just used it to match newline characters with \n.  I think this issue can be closed.
Comment 11 markiewb 2014-03-15 08:29:58 UTC
(In reply to swpalmer from comment #10)
> Regexp search/replace is working in NB 8.0 FCS build.  I just used it to
> match newline characters with \n.  I think this issue can be closed.

I do not think so. The request [1] was to paste in text which has linebreaks and which isn't formatted as regex.

[1] https://netbeans.org/bugzilla/show_bug.cgi?id=148989#c0
Comment 12 rhp195 2014-04-01 22:45:18 UTC
I also don't think this should be closed. The functionality needed is to allow the user to select text in the editor and find other occurrences of that selected text at least within the current document.

For me, I want to be able to find duplicate blocks of code in order to identify functionality that can be replaced with more maintainable functions.
Comment 13 lindberg123 2014-04-22 12:28:19 UTC
Bump. Really, without this in my workflow I consider stop using Netbeans. I started using it today. This is such a simple but useful thing to create. Have I missed anything? I dont want to convert things on the fly to regex. 

Sometimes I just want to do a fast search marking text .. 
- copy
- ctl+f
- paste
- enter
.. and editor jumps to line

Even Dreamweaver has this since 2005.
Comment 14 Miloslav Metelka 2014-05-14 14:40:41 UTC
(In reply to lindberg123 from comment #13)
> Sometimes I just want to do a fast search marking text .. 
> - copy
> - ctl+f
> - paste
> - enter
> .. and editor jumps to line

NetBeans has Ctrl+F3 to search either selected text or an identifier under cursor (if no selection is present).
Comment 15 ulfzibis 2014-08-02 15:53:15 UTC
I think, 10 votes can be considered as more than P4.
Comment 16 hans_adler 2014-10-12 08:40:05 UTC
Here is a concrete example of something that should work, but doesn't. Ages ago, in code that I am cleaning up, a tool created lots of named queries that were never used. They are still present in 75 files and look like this:

@NamedQueries({
  @NamedQuery(name = ..., query = ...),
  @NamedQuery(name = ..., query = ...),
  @NamedQuery(name = ..., query = ...),
  @NamedQuery(name = ..., query = ...),
  ...
})

I tested the following regular expression in a search:

@NamedQueries\(\{.*?\}\)

But the matching appears to be done line by line, so this doesn't work. If it did, I would be able to clean up all files in a single operation.

There should be an option for global matching rather than line-by-line matching. I think that would also take care of the original request. The default for this option should be single-line search except when multiline text is pasted into the search field. For multi-line search in Literal and Basic Wildcards mode, the "containing text" field should be a text area. In Basic Wildcards mode, * and ? should not match text containing line breaks, and any style of literal line break (\n, \r, \r\n) should match any style of line break in the files.
Comment 17 headbank 2015-04-05 14:05:06 UTC
(In reply to swpalmer from comment #10)
> Regexp search/replace is working in NB 8.0 FCS build.  I just used it to
> match newline characters with \n.  I think this issue can be closed.

No. Until there is support for multiline wildcard matching, it's nowhere near ready to be closed.

To add insult to injury, multiline regex may work in the "test" flyout, but not when applied.

Find/replace Regex to find HTML FORM opening tags which may be broken over multiple lines:

<form([^>]*)>

Sample text:

<form name="foo"
action="/foo.php">

Matches in the test flyout, *does not match* when applied to project files. (8.0.2)

Inconsistency like that makes the test function rather pointless. It's hard to even comprehend in what kind of design the two could behave differently.

There is neither support for in-line modifiers such as (?s), nor UI features (more checkboxes) to set them pattern-wide (apart from "i"). If you are going to cite java-util.regex.Pattern syntax right there in the UI, how about supporting it?
Comment 18 headbank 2015-04-05 14:43:20 UTC
Incidentally, there is one method (hilariously elaborate) to achieve a multiline match in NetBeans search/replace for the example above, thanks to at least having explicit matching capability now as you point out:

<form((?:[^>]|\n|\r)*)>

So yes, if we look for "anything except '>', OR a newline, OR a carriage-return", we're in business.

PS - I've just received two bounces from CCs' mail servers, forwarded back to me by the Oracle mail server after making the above comment, so now I know two of the CC list's real email addresses (albeit both AWOL or defunct). If you're going to go to the trouble of giving us all "masking" email addresses (can't see the point of this myself), you might try to ensure the mask stays on the face, eh?
Comment 19 SebastianZ 2015-11-20 06:55:57 UTC
Some comments suggest that you should be able to select some text and by pressing Ctrl+F the text should be copied to the 'Find What' field as valid regular expression.

Does this also include to escape characters, which are special tokens in regexes, like brackets and dots?

Eg. if I select this from comment 16:

@NamedQueries({
  @NamedQuery(

and press Ctrl+F to start searching, I'd espect this to be in the find field when searching for regular expressions is enabled:

@NamedQueries\(\{\n  @NamedQuery\(

Or should I create a separate bug for escaping brackets, dots, question marks, etc.?

Sebastian
Comment 20 egemenk 2015-12-16 03:45:13 UTC
I had used Netbeans and left years ago. Recently I decided to give it a try and really loved it; so many improvements since I last used it. But it's unbelievable that it still lacks a multi-line search/replace and that's a total deal-breaker for me. Having a multi-line text input and being able to make a simple text search with that input contents shouldn't be too hard to implement. It's not regex, just plain text search. It really comes handy being able to select chunks of code and copy/paste it into search input and paste some other multi-line code to replace input - and have all occurrences replaced. Even some basic editors have this.
Comment 21 bht 2016-09-26 03:43:16 UTC
It would perhaps be one of the most basic refactoring features. Say if you want to replace code containing 5 lines of code in a set order with a method call. How many times did I get RSI and bloody eyes doing this kind of thing? What is the human error rate? What is the point of running PMD CPD if my IDE does not give me any action to do anything with the output? I feel like an idiot while AI is everywhere around me.
Comment 22 ulfzibis 2016-09-26 10:34:33 UTC
(In reply to bht from comment #21)
I'm with you with the part I understand, but can you please explain the abbreviations, so I can understand the other parts.
Comment 23 bht 2016-09-26 13:08:03 UTC
These acronyms were for RSI = Repetitive strain injury, PMD CPD is the tool that finds duplication in source code, AI = Artificial Intelligence. What I meant to say is that computers are fairly smart today, and that there is perhaps some catching up to do. But I must admit that the solution is not trivial if it is really useful, so perhaps that could be a field for a plugin.