Regex to extract substring from a tag

I have a dateset where I measure curl performance on a set of files from a server. I have stored the entire url as a tag so the data is on this format:

curl,probe=probe10,url="http://example.com/10k.html"  download_time=0.01
curl,probe=probe10,url="http://example.com/100k.html"  download_time=0.02
curl,probe=probe10,url="http://example.com/1000k.html"  download_time=0.1

This works fine for grouping and matching - but displaying is ugly when the entire url is displayed. Is there a way to use map() or another function where I could extract only filename part of the URL and use as tag?

Perhaps something along these lines?

 |> map(fn:(r) => ({ _time:r._time,download:r._value, file: r.url =~ /example.com\/(.+)$/}))

Hello @eriktar,
How about?

import "array"
import "strings"

data = array.from(rows: [{_time: 2020-01-01T00:00:00Z, url: "http://example.com/10k.html"},{_time: 2020-01-02T00:00:00Z, url: "http://example.com/11k.html"}])
|> yield(name:"raw")


data 
|> map(fn: (r) => ({ r with url: strings.trimLeft(v: r.url, cutset: "http://example.com/") }))

I’d recommend looking at the strings package in general:

That strings.trimLeft did the job. Thanks a lot!

And I’ll be reading up on the other functions in stings. Good to be able to format the ouput a bit every once in a while.

1 Like