正则表达式匹配两个单独的短语

[英]Regular Expression to match two separate phrases


I am looking for a regular expression that can ensure two phrases showing up on a webpage at the same time.

我正在寻找一个正则表达式,可以确保同时在网页上显示两个短语。

The two phrases I need to ensure on the web are Current QPS (last 10s, ignored 0) and Average Latency (last 100 queries)

我需要在网络上确保的两个短语是当前QPS(过去10秒,忽略0)和平均延迟(最后100个查询)

The webpage looks like (The query time would be different, but text won't change):

网页看起来像(查询时间会有所不同,但文字不会改变):

Query Statistics

Average QPS 25.3673   
Average Latency 0.1002   
Average Latency (last 100 queries) 0.0834   # Match this one, ignore output-0,0834
Average Search Latency 0.0555   
Average Docsum Latency 0.0330   
Sampling period 3133524.9570   
Current QPS (last 10s, ignored 0) 24.8000  # Also match this one, ignore output 24.8000 
Peak QPS 170.9000   
Number of requests 79717858   
Number of queries 79489080 

I am able to match each phrase on the website, but not the two phrases together. How can I make my tool ignore the content between the two phrases?

我能够匹配网站上的每个短语,但不能匹配两个短语。如何让我的工具忽略两个短语之间的内容?

P.S. I am not programming in any language here, the regex will be put into a tool that accepts regex.

附:我不是在这里用任何语言编程,正则表达式将被放入一个接受正则表达式的工具。

4 个解决方案

#1


5  

If you can be sure that they will appear in that order, if at all, then this should work:

如果您可以确定它们将以该顺序出现,如果有的话,那么这应该有效:

(<query 1>).*(<query 2>)

E.g.

(Average Latency \(last \d+ queries\)).*(Current QPS \(last \d+s, ignored \d+\))

You may need to check that the . operator matches newlines in your tool.

你可能需要检查一下。运算符匹配工具中的换行符。

#2


1  

my first suggest is to simply add the two patterns in your regular expression in any order you expect them to appear

我的第一个建议是简单地按照您希望它们出现的任何顺序在正则表达式中添加这两个模式

/($regex1.*?$regex2|$regex2.*?$regex1)/

#3


0  

It might depend on the tool you're using--specifically, how it handles multiple lines.

它可能取决于您正在使用的工具 - 具体来说,它如何处理多行。

You can try this:

你可以试试这个:

Average Latency \(last \d+ queries\)\s(.*\s)*Current QPS \(last \d+s, ignored \d+\)\s

#4


0  

This should work

这应该工作

(?im)^(Average\s+Latency\s+\(last\s+100\s+queries\)|Current\s+QPS\s+\(last\s+10s,\s+ignored\s+0\)).+
智能推荐

注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:http://www.itdaan.com/blog/2012/06/12/7201e6ffb999805948f8369fa83fbc6d.html



 
© 2014-2019 ITdaan.com 粤ICP备14056181号  

赞助商广告