最近在netbeans的替换功能中使用正则表达式中的反向引用,总是不成功,网上找资料也不容易,找了很久,终于在oracle的blog找到了答案。
原来netbeans的替换支持反向引用,只是他是使用$0、$1进行反向引用的,如果习惯了使用\1、\2的,要改改了。
原文如下:
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 :-)
分享到:
相关推荐
基于JAVA开发的自然语言正则表达式分析 程序, netbeans
使用的类如下: 正则表达式语法树二叉树节点叶节点DfaTraversal 州这是一个在主函数中调用的初始化方法: public static void initialize() { DStates = new HashSet<> (); input = new HashSet< String> (); ...
在Netbeans中使用Struts2.0+Spring2.5+Hibernate框
NetBeans.NetBeans中添加背景图片附源码。
NetBeans6.0中使用WebServices
在NetBeans6.0中使用WebService.入门知识。
另外在过滤器内部进行路径排除的时候,使用了正则表达式匹配, 因此lib目录还包含了正则表达式的jar包commons-lang3-3.5.jar。 2. 进入mysql的test数据库,运行test.sql 文件的sql命令,首先创建好数据库表(建议...
如何使用NetBeans编译Java程序.
NetBeans+IDE+使用说明和示例教程.pdf
以下是Java程序员在日常生活中最常用的10种工具。...Edit Plus最优秀的地方是它非常快速、流畅,并支持所有正则表达式的查找和替换任务。Notepad++可以打开任何类型的Java文件,甚至包含了未在IDE配置的文件,
让Struts2 在NetBeans 6中安家
51CTO下载-NetBeans+IDE+使用说明和示例教程.docx
Apache-NetBeans 21安装包
Netbeans环境下使用GTK+. Netbeans环境下使用GTK+.
NetBeans是新近流行的一款堪与Eclipse媲美的IDE,有Sun的支持。下面是NetBeans使用教程入门篇。
演示在netBeans6.5中如何定义和引用自定义库,第三方库(如JDBC驱动、JSTL库等),这是入门时使用的一种方法,在使用熟悉后,可以灵活使用多种方法来添加外部库。
在实际开发中教您NetBeans的使用图解
如何在NetBeans中连接MySQL数据库
第五篇给出了如何在NetBeans中进行C/C++程序的开发方法。 本书内容深入浅出,实例丰富,可帮助读者快速入门,适合希望使用NetBeans进行开发的初、中、高级读者,可作为必备的开发工具书使用。
第五篇给出了如何在NetBeans中进行C/C++程序的开发方法。 NetBeans是当前市场上最为流行的、源代码开放且免费的集成开发环境。NetBeans不仅可以作为Java开发工具,还可以使用它开发标准的Java程序、Web应用程序、...