Regexp Search in NetBeans
By Roman Strobl on III 31, 2005
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 :-)