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)
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.
to combine two expressions or more, put every expression in brackets, and use: *? This are the signs to combine, in order of relevance: ?
To split a string by a regular expression, pass a regex as a parameter to the split() method, e.g. str. split(/[,. \s]/) . The split method takes a string or regular expression and splits the string based on the provided separator, into an array of substrings.
However, to recognize multiple words in any order using regex, I'd suggest the use of quantifier in regex: (\b(james|jack)\b. *){2,} . Unlike lookaround or mode modifier, this works in most regex flavours.
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.
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)/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With