package main
import (
"regexp"
"fmt"
)
func main() {
var re = regexp.MustCompile(`(?m)^source=(?P<pg_db_name>[^\s]+)\s*addon=(?P<addon_name>[^\s]+)\s*sample#current_transaction=(?P<transactionID>[^\s]+)\s*sample#db_size=(?P<db_size>[^\s]+)\s*sample#tables=(?P<numebr_of_tables>[^\s]+)\s*sample#active-connections(?P<numebr_of_active_conenctions>[^\s]+)\ssample#waiting-connections=(?P<numebr_of_waiting_conenctions>[^\s]+)\s*sample#index-cache-hit-rate=(?P<index_cache_hit_rate>[^\s]+)\s*sample#table-cache-hit-rate=(?P<table_cache_hit_rate>[^\s]+)\s*sample#load-avg-1m=(?P<load_avg_1m>[^\s]+)\s*sample#load-avg-5m=(?P<load_avg_5m>[^\s]+)\s*sample#load-avg-15m=(?P<load_avg_15m>[^\s]+)\s*sample#read-iops=(?P<Number_read_ops>[^\s]+)\s*sample#write-iops=(?P<Number_write_ops>[^\s]+)\s*sample#tmp-disk-used=(?P<tmp_disk_used>[^\s]+)\s*sample#tmp-disk-available=(?P<tmp_disk_available>[^\s]+)\s*sample#memory-total=(?P<total_memory>[^\s]+)\s*sample#memory-free=(?P<free_memory>[^\s]+)\s*sample#memory-cached=(?P<cached_memory>[^\s]+)\s*sample#memory-postgres=(?P<postgres_memory>[^\s]+)`)
var str = `source=HEROKU_POSTGRESQL_CYAN addon=postgresql-parallel-49130 sample#current_transaction=1491116935 sample#db_size=70416175775bytes sample#tables=172 sample#active-connections=173 sample#waiting-connections=0 sample#index-cache-hit-rate=0.99768 sample#table-cache-hit-rate=0.99892 sample#load-avg-1m=0.26125 sample#load-avg-5m=0.205 sample#load-avg-15m=0.2175 sample#read-iops=4.0167 sample#write-iops=62.383 sample#tmp-disk-used=33849344 sample#tmp-disk-available=72944943104 sample#memory-total=62879916kB sample#memory-free=578624kB sample#memory-cached=57198556kB sample#memory-postgres=1246028kB`
for i, match := range re.FindAllString(str, -1) {
fmt.Println(match, "found at index", i)
}
}
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for Golang, please visit: https://golang.org/pkg/regexp/