Skip to content

Instantly share code, notes, and snippets.

@eloycoto
Created September 18, 2017 17:34
Show Gist options
  • Save eloycoto/455b5bff957e96a8a9f48fe608a67d47 to your computer and use it in GitHub Desktop.
Save eloycoto/455b5bff957e96a8a9f48fe608a67d47 to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"regexp"
)
func main() {
// Compile the expression once, usually at init time.
// Use raw strings to avoid having to quote the backslashes.
var validID = regexp.MustCompile(`^jsonpath\=(.*)`)
fmt.Println(validID.MatchString("jsonpath='{.items[?(@.spec.nodeName == \"MERDA\")].metadata.name}'"))
fmt.Println(validID.ReplaceAllString("jsonpath='{.items[?(@.spec.nodeName == \"MERDA\")].metadata.name}'", "$1"))
fmt.Println(validID.MatchString("eve[7]"))
fmt.Println(validID.MatchString("Job[48]"))
fmt.Println(validID.MatchString("snakey"))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment