Another Regexp Trick in NetBeans



Question: How do I replace two newlines by one in the whole file?

Answer: Not trivial :-) We've added regexp support recently into NetBeans (see my other post about back-references). You can certainly use "\\n" in the Find What field. Now you want to replace "\\n\\n" by "\\n". If you try to do this, it doesn't work, because the Replace With field converts \\n to just n (not to a newline). Too bad we can't use this kind of expressions in the Replace With field but we have to live with that for now.

But! You can use a back-reference to get the \\n into the Replace With field like this:


Using this neat trick you can replace two newlines by one. It can be used not only for newlines, but any other similar expressions starting by backslash.
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