Another nice feature of Kusto / Application Insights Analytics is full on support for regular expressions using the extract keyword.
A very useful application of this is all matter of manipulations you can do over the “url” field in requests. A common ask is understanding how much traffic is generated by any of your different hosts.
Since Analytics only carries the full url field, we need to parse out the host out using a regex. I took a really really simple regex in this case, but obviously it can be much more complex.
pageViews | where timestamp > ago(1d) | extend urlhost=extract('^(http://|https://)([^:\\/\\s]+)', 2, url) | summarize count() by urlhost | render piechart
There is now a simpler method to extract all url parts – parseurl.
requests | take 5 | extend urlParts = parseurl(url) | project url, urlParts, urlParts.Scheme, urlParts.Host, urlParts.Path, urlParts.Port