正則表達式匹配兩個單獨的短語

[英]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\)).+

注意!

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



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