Go VerbalExpressions implementation
VerbalExpression is a concept to help building difficult regular expressions.
See online doc here: http:https://godoc.org/github.com/VerbalExpressions/GoVerbalExpressions
You can see an up to date list of all ports in our organization.
Use this command line:
go get github.com/VerbalExpressions/GoVerbalExpressions
This will install package in your $GOPATH and you will be ready to import it.
// import with a nice name
import (
verbalexpressions "github.com/VerbalExpressions/GoVerbalExpressions"
"fmt"
)
func main () {
v := verbalexpressions.New().
StartOfLine().
Then("http").
Maybe("s").
Then( ":https://").
Maybe("www.").
AnythingBut(" ").
EndOfLine()
testMe := "https://www.google.com"
if v.Test(testMe) {
fmt.Println("You have a valid URL")
} else {
fmt.Println("URL is incorrect")
}
}
We try to give alias method and/or helpers. For example:
// s will be "We have a blue house"
s := verbalexpressions.New().Find("red").Replace("We have a red house", "blue")
// c will be:
// [
// ["http:https://www.google.com", "http:https://", "www.google.com"]
// ]
c := verbalexpressions.New().
BeginCapture().
Find("http").Maybe("s").Find(":https://").
EndCapture().
BeginCapture().
Find("www.").Anything().
EndCapture().
Captures("http:https://www.google.com")
// check c[0][1] => http:https://
// c[0][2] => www.google.com