I have this test string, which I want to extract data from using Regex:
"-> Single-row index lookup on using <auto_distinct_key> (actor_id=actor.actor_id) (cost=901.66 rows=5478) (actual time=0.001..0.001 rows=0 loops=200)"
The six fields of data that I want to extract are written in bold. The segment that is written in italic is the optional part of the statement.
This is the pattern which I have arrived at thus far:
-> (.+) (\(cost=([\d\.]+) rows=(\d+)\))? \(actual time=([\d\.]+) rows=(\d+) loops=(\d+)\)
This gives me six groups with all the data I want. However, when I omit the optional part of the string it does not match at all. I suspected this was due to superfluous whitespaces, so I thought it might work to move the whitespace into the optional group, like this:
-> (.+)( \(cost=([\d\.]+) rows=(\d+)\))? \(actual time=([\d\.]+) rows=(\d+) loops=(\d+)\)
Which did not work.
It seems to match the optional group as part of the first group, which is not really what I want. I want them separate, and I'm not quite sure how to do that.