From: Peter Booth Date: 2018-06-21T08:45:18-04:00 Subject: [ruby-core:87574] Yes idiom to shorten a long regex --===============0871095654== Content-type: multipart/alternative; boundary="Apple-Mail=_33790B76-BF72-44F6-AAB4-0D7A08E0C3AD" --Apple-Mail=_33790B76-BF72-44F6-AAB4-0D7A08E0C3AD Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=us-ascii Hello, I have some data that I would like to parse with a regex. The raw data = looks like so: 9.028: I:4551 ( 0.095 0.096 0.136 ) T:4551 ( 0.095 0.096 = 0.098 0.117 0.136 0.136 ) 14.066: I:4601 ( 0.095 0.096 5.344 ) T:9152 ( 0.095 0.096 = 0.098 0.119 4.352 5.344 ) 19.099: I:4609 ( 0.094 0.096 0.132 ) T:13761 ( 0.094 0.096 = 0.098 0.123 4.352 5.344 ) 24.033: I:4528 ( 0.093 0.095 0.130 ) T:18289 ( 0.094 0.096 = 0.098 0.124 3.344 5.344 ) I can extract the data that I want with the following: ^(\d+\.\d+): = I:\d+\s+\(\s+(\d+\.\d+)\s+(\d+\.\d+)\s+(\d+\.\d+)\s+\).+\(\s+(\d+\.\d+)\s+= (\d+\.\d+)\s+(\d+\.\d+)\s+(\d+\.\d+)\s+(\d+\.\d+)\s+(\d+\.\d+)\s+\)$ I can even name the fields with the longer: ^(?\d+\.\d+): = I:\d+\s+\(\s+(?\d+\.\d+)\s+(?\d+\.\d+)\s+(?\d+\.\d+)\s+\).+\(\s+(\d+\.\d+)\s+(\d+\.\d+)\s+(\d+\.\d+)\s+(\d+\.\d+= )\s+(\d+\.\d+)\s+(\d+\.\d+)\s+\)$ But that's a long ugly regex that repeats the {capture+whitespace} = element (\d+\.\d+)\s+ three times, then six times=20 Is there a Ruby regex way to simplify/clarify the regex so that it = explicitly shows that the capture+whitespace is repeated three times = then six ? thanks, Peter --Apple-Mail=_33790B76-BF72-44F6-AAB4-0D7A08E0C3AD Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=us-ascii Hello,

I = have some data that I would like to parse with a regex. The raw data = looks like so:

9.028: = I:4551 (   0.095   0.096   0.136 ) T:4551 (   0.095 =   0.096   0.098   0.117   0.136   0.136 = )
14.066: = I:4601 (   0.095   0.096   5.344 ) T:9152 (   0.095 =   0.096   0.098   0.119   4.352   5.344 = )
19.099: = I:4609 (   0.094   0.096   0.132 ) T:13761 (   0.094 =   0.096   0.098   0.123   4.352   5.344 = )
24.033: = I:4528 (   0.093   0.095   0.130 ) T:18289 (   0.094 =   0.096   0.098   0.124   3.344   5.344 = )

I= can extract the data that I want with the following:

^(\d+\.\d+): = I:\d+\s+\(\s+(\d+\.\d+)\s+(\d+\.\d+)\s+(\d+\.\d+)\s+\).+\(\s+(\d+\.\d+)\s+= (\d+\.\d+)\s+(\d+\.\d+)\s+(\d+\.\d+)\s+(\d+\.\d+)\s+(\d+\.\d+)\s+\)$

I can even = name the fields with the longer:

^(?<offset_secs>\d+\.\d+): = I:\d+\s+\(\s+(?<median_stall>\d+\.\d+)\s+(?<p90_stall>\d+\.\d+= )\s+(?<max_stall>\d+\.\d+)\s+\).+\(\s+(\d+\.\d+)\s+(\d+\.\d+)\s+(\d+= \.\d+)\s+(\d+\.\d+)\s+(\d+\.\d+)\s+(\d+\.\d+)\s+\)$

But that's a long ugly = regex that repeats the {capture+whitespace} element (\d+\.\d+)\s+  three times, then six = times 

 Is there a Ruby regex way to simplify/clarify the regex = so that it explicitly shows that the capture+whitespace is repeated = three times then six ?




thanks,

Peter


= --Apple-Mail=_33790B76-BF72-44F6-AAB4-0D7A08E0C3AD-- --===============0871095654== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline Unsubscribe: --===============0871095654==--