2016-03-03 43 views
0

我想用正则表达式得到2个或更多3个单词。但我很难得到这些单词而不是全部。正则表达式在一条线上得到2个特定单词

下面是文字。

3255 2010-02-14 13:17:14 WARN HA在接下来的600秒内禁用警报。策略仍在执行

3256 2010-02-14 13:18:17 WARN UDM自适应筛选配置禁用筛选“13379:HTTP:酷PDF图像流长度缓冲区溢出漏洞”[00000002-0002-0002-0002-0002-000000013379 ]

正则表达式我用的是

\d{4}-\d{2}-\d{2}.*disabled filter.*$ -> this work but will get the whole line. 

我试图让只有日期和文字禁用过滤器,

前。 2016年2月14日13时十八分17秒过滤器“13379:HTTP:酷PDF图像数据流长度的缓冲区溢出漏洞”

我试图用管,但它也将获得另一个日期在另一条线路

[0-9]{4}-[0-9]{2}-[0-9]{2}|disabled filter|"[0-9]{5}.+" 

任何人都可以帮忙吗?

+0

? Python,Perl,Java等? – Saleem

+0

我用notepad ++和崇高文本在正则表达式上使用find/search。 – Nekro

+0

好的,请在我的文章中看到。我发布了几个正则表达式,包括Notepad ++ – Saleem

回答

0

由于缺少语言,因此以下几种解决方案。

的Python

match = re.search('(?<=disabled filter ")[^"]+', subject, re.IGNORECASE | re.MULTILINE) 
if match: 
    result = match.group() 

的Java

Pattern regex = Pattern.compile("(?<=disabled filter \")[^\"]+", Pattern.CASE_INSENSITIVE | Pattern.UNICODE_CASE | Pattern.MULTILINE); 
Matcher regexMatcher = regex.matcher(subjectString); 
if (regexMatcher.find()) { 
    ResultString = regexMatcher.group(); 
} 

记事本++和崇高文本

(\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2})(?:.*)(?<=disabled filter ")([^"]+) 

组(1)将有date和集团(2)包含filter您正在使用什么语言

相关问题