CTRL + space in the textboxes gives you all kinds of suggestions for regular expression writing.

查找

替换

Be sure to check out the \C regular expression operator, which I think is specific to Eclipse.

It saves a lot of work in replacing the same word in upper-case, lower-case, and camelCase variants.

For example, if the original text is:

SomeObject someObject = SOMEOBJECT;

then doing a "Replace All" replacing

someObject

with 

\CanotherObject

will get you:

AnotherObject anotherObject = ANOTHEROBJECT;

https://dzone.com/articles/using-regular-expressions

I had an old method with hundreds of lines doing calling a getAttribute("X") and casting the result to a string.

(String)object1.getAttribute("X")
(String)object2.getAttribute("Y")
(String)objectN.getAttribute("Z")

I had to change them all to use a new method that checks if the attribute is null. So the new line would be

getSafeStringAttribute(object1,"X")
getSafeStringAttribute(object2,"Y")
getSafeStringAttribute(objectN,"Z")

With this simple regEx you can do a replace all!

find :

\(String\)(.+)\.getAttribute\("(.+)"\)

replace
 
getSafeStringAttribute($1,"$2")

The first (.+) will match the objectX part while the second will match the attribute name.

The best thing is that when you select some text and

type CTRL + F (if the Regular Expressions checkbox is ticked)

you string in the find will be already escaped from characters like '(', ')' etc!

Eclipse 正则表达式 查找与替换的更多相关文章

  1. 在VS中用正则表达式查找或替换

    2005VS和2008VS正则替换规则如下(2013VS不适合,不需要的同学可以直接跳到2013VS的操作办法): Example: 查找#incldue中带有gl开头的头文件的,用include.+ ...

  2. Java基础之一组有用的类——使用正则表达式查找和替换(SearchAndReplace)

    控制台程序. 使用正则表达式执行查找和替换操作,只需要调用Matcher对象的find()方法,就可以调用appendReplacement()方法来替换匹配的子序列.在提供给方法的新StringBu ...

  3. VisualStudio2010正则表达式查找和替换

    把 TRACE(_T("something etc."); 替换为 TRACE(_T("something etc."));查找内容:表达式:TRACE\(_T ...

  4. UE正则表达式查找和替换(将【,;】)替换为换行

  5. 在UltraEdit的查找和替换中使用正则表达式 (转)

    很多朋友都用过或者正在用UltraEdit,这个编辑器陪伴我也好几年了,从很多地方影响着我写代码的快捷键习惯,Ultraedit提供了非常丰富的编辑功能,其中非常重要的查找和替换功能一定大家都用过,U ...

  6. VIM正则表达式查找替换

      0. 一些需要注意的不同 VIM中的正则表达式和其他的有点不一样 (1) 有些符号要用\转义,比如\+表示重复一次或以上,其他的还有一些,:h pattern查看(2) 非贪婪匹配用\{-}, 如 ...

  7. xcode中使用正则表达式来搜索替换代码

    有这样的需求: 类似于 GLOBAL_STR(@"请继续添加"); 这样的代码,需要批量修改为: GLOBAL_STR(@"请继续添加", nil); 这里使用 ...

  8. linux shell 字符串操作(长度,查找,替换)详解

    linux shell 字符串操作(长度,查找,替换)详解 在做shell批处理程序时候,经常会涉及到字符串相关操作.有很多命令语句,如:awk,sed都可以做字符串各种操作. 其实shell内置一系 ...

  9. visual studio 使用正则查找或替换示例

    visual studio 使用正则查找或替换示例 注意哟:使用之前应做好备份 visual studio 2015: 多行替换 (.*)point\ =(.*);\r\n.+this.([A-Za- ...

随机推荐

  1. Linux - ssh 连接慢解决

    解决 ssh 链接慢 sed -i 's/GSSAPIAuthentication yes/GSSAPIAuthentication no/' /etc/ssh/sshd_config sed -i ...

  2. Ubuntu接显示器问题

    1.Could not apply the stored configuration for monitors 解决办法:Ubuntu在开机进入桌面的时候,会调用gnome-setting-deamo ...

  3. Android的layout_weight和weightSum

    先看一下weightSum属性的功能描述:定义weight总和的最大值.如果未指定该值,以所有子视图的layout_weight属性的累加值作为总和的最大值.把weightSum的定义搁在这里,先去看 ...

  4. linux下简单的备份的脚本 2 【转】

    转自:http://blog.chinaunix.net/xmlrpc.php?r=blog/article&uid=26807463&id=4577034 之前写过linux下简单的 ...

  5. 新手学习爬虫之创建第一个完整的scrapy工程-糗事百科

    创建第一个scrapy工程-糗事百科 最近不少小伙伴儿,问我关于scrapy如何设置headers的问题,时间久了不怎么用,还真有的忘,全靠记忆去写了,为了方便大家参考,也方便我以后的查阅,这篇文章就 ...

  6. java虚拟机规范(se8)——java虚拟机结构(五)

    2.10 异常 java虚拟机中的异常用Throwable类或者它的子类的实例来表示.抛出一个异常会导致立即非本地(an inmediate nolocal)的控制转移,从发生异常的地方跳到处理异常的 ...

  7. 织梦任意页面调用{dede:field.content/}的方法

    过滤掉所有的html代码,只显示文字,具体的ID自己更改. 代码如下: {dede:sql sql='Select content from dede_arctype where id=1'} [fi ...

  8. LeetCode(16):最接近的三数之和

    Medium! 题目描述: 给定一个包括 n 个整数的数组 nums 和 一个目标值 target.找出 nums 中的三个整数,使得它们的和与 target 最接近.返回这三个数的和.假定每组输入只 ...

  9. Spring AOP实现原理-动态代理

    目录 代理模式 静态代理 动态代理 代理模式 我们知道,Spring AOP的主要作用就是不通过修改源代码的方式.将非核心功能代码织入来实现对方法的增强.那么Spring AOP的底层如何实现对方法的 ...

  10. 下载vc++运行库

    之前下载vc++运行库都是百度,从中关村.当下等软件网站下载,但是最近这些网站涉及到安全问题,所以从官网下载比较合适 微软官网-中文 在搜索中 搜索vc++2010/2015等,搜索结果中找到xxxx ...