正则表达式查找包含一个单词而不是另一个单词的文件 [英] regex to find files containing one word but not another

查看:118
本文介绍了正则表达式查找包含一个单词而不是另一个单词的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试快速查找包含一个术语但缺少另一个术语的所有.java文件。我使用MyEclipse 10.7及其搜索文件搜索功能,支持正则表达式。

I am trying to quickly find all .java files which contain one term but are missing another term. I'm using MyEclipse 10.7 and its 'Search | File Search' feature, which supports regular expressions.

在这种情况下,正则表达式是否正常工作?正确的正则表达式是什么?

Will regex work in this scenario? What would the correct regex be?

TIA,
Steve

TIA, Steve

推荐答案

我可以找到工作的唯一解决方案是以下正则表达式:

The only solution I could find to work is the following Regex:

^(?!.[\s\S]*MISSING_TERM).[\s\S]*INCLUDED_TERM.*$

它发现每个包含 INCLUDED_TERM 的文件,但是缺少 MISSING_TERM ,而不管行。

It finds every file which includes INCLUDED_TERM but lacks MISSING_TERM, regardless of the line.

关键是 \s\S ,确保整个文件被搜索,而不是每一行。

The key is the \s\S, which ensures the whole file is searched and not each line.

这篇关于正则表达式查找包含一个单词而不是另一个单词的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆