Regexp Search in NetBeans



We've recently added regular expression support into the Find dialog in NetBeans (the Ctrl-F one). Works like charm for both find and replace. But not for all users. Several days after commit we've got user feedback: "But you don't support back-references". "Sure we do". "They don't work for me".

So the problem is that there are two types of back-references. One type which is denoted as $1 and one as \\1. NetBeans uses the $1 one which is used normally in Java. However some other parts of the world are using \\1.

So how do we tell users which one they have to use? Nobody really reads documentation so perhaps we need to tell users in the dialog. If they try to use \\1, we should politely ask them if they didn't want to use $1. Sigh, why can't there be just one standard for everything? :-)

For those who do not know what back-references are, here is my explanation:

Back-references are a very useful when replacing some text. You have the following text: "Hello, world". Now, you can do following:


If you replace the text like this in NetBeans, the result is: "Farewell, world". One replace is not much useful, but imagine if you have a long file where you need to do many replaces and a the file's more complicated. You can use $2, $3, etc. for next elements in parentesis if you want to replace more of them at once. $0 is used for the whole searched string.

This feature can certainly save you a lot of time you would spend by manual editing. And you can impress other people with it as well :-)
Comments:

Post a Comment:
Comments are closed for this entry.
About

Roman Strobl

Search

Archives
« duben 2014
PoÚtStČtSoNe
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
    
       
Today