ruby - regex match one instance of a pattern that repeats -
given following regex
/(500 internal server error)/ how match 1st occurrence of pattern in single string has many repeats of same match?
for example:
match 1 1. 500 internal server error match 2 1. 500 internal server error match 3 1. 500 internal server error how 1. our answer?
sample text match follows (one big string on purpose)
[soapuimultithreadedhttpconnectionmanager$soapuidefaultclientconnection] receiving response: http/1.1 500 internal server error12:09:26,638 info [soapuiprotestcaserunner] assertion [match content of [question]] has status valid12:09:26,638 debug [soapuimultithreadedhttpconnectionmanager$soapuidefaultclientconnection] connection 0.0.0.0:41494<->23.6.55.1:80 shut down12:09:26,638 debug [soapuimultithreadedhttpconnectionmanager$soapuidefaultclientconnection] connection 0.0.0.0:41494<->23.6.55.1:80 closed12:09:26,638 info [soapuiprotestcaserunner] finished running soapui testcase [test_fieldsparameter], time taken: 384ms, status: finished12:09:26,640 info [soapuiprotestcaserunner] assertion [match content of [errorcode]] has status valid12:09:26,641 info [soapuiprotestcaserunner] assertion [match content of [message]] has status valid12:09:26,641 info [soapuiprotestcaserunner] assertion [valid http status codes] has status valid12:09:26,641 info [soapuiprotestcaserunner] running step [othersortby]12:09:26,643 debug [httpclientsupport$soapuihttpclient] stale connection check12:09:26,645 debug [httpclientsupport$soapuihttpclient] attempt 1 execute request12:09:26,646 debug [soapuimultithreadedhttpconnectionmanager$soapuidefaultclientconnection] sending request: /api/review/v1/questions?prodid=570043&_sortby=other http/1.112:09:26,666 debug [soapuimultithreadedhttpconnectionmanager$soapuidefaultclientconnection] receiving response: http/1.1 500 internal server error12:09:26,667 debug [soapuimultithreadedhttpconnectionmanager$soapuidefaultclientconnection] connection 0.0.0.0:41475<->23.6.55.1:80 shut down12:09:26,667 debug
please have look, proves string captured first:
str = "match 1\n1. 500 internal server error\nmatch 2\n1. 500 internal server error\nmatch 3\n1. 500 internal server error" re = /(500 internal server error)/ mdata = re.match(str) puts mdata.begin(1) puts mdata output of sample program proving first occurrence (index of 12 in input string):
12 500 internal server error
Comments
Post a Comment