sshpoke/internal/server/driver/ssh/regexp.go

29 lines
892 B
Go
Raw Normal View History

package ssh
import (
"fmt"
"regexp"
"strings"
)
var builtInRegExps = map[string]*regexp.Regexp{
"webUrl": regexp.MustCompile(`(?m)https?:\/\/(?:www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b(?:[-a-zA-Z0-9()@:%_\+.~#?&\/=]*)`),
"httpUrl": regexp.MustCompile(`(?m)http:\/\/(?:www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b(?:[-a-zA-Z0-9()@:%_\+.~#?&\/=]*)`),
"httpsUrl": regexp.MustCompile(`(?m)https:\/\/(?:www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b(?:[-a-zA-Z0-9()@:%_\+.~#?&\/=]*)`),
}
func makeDomainCatchRegExp(expr string) (*regexp.Regexp, error) {
if expr == "" {
return nil, nil
}
if strings.HasPrefix(expr, "!") {
exprName := expr[1:]
builtIn, found := builtInRegExps[exprName]
if !found {
return nil, fmt.Errorf("no builtin regexp with name '%s'", exprName)
}
return builtIn, nil
}
return regexp.Compile(expr)
}