示例#1
0
func compile(expr string) (Regexp, error) {
	r, _, err := syntax.Compile(expr)
	if err != nil {
		return nil, err
	}
	return r, nil
}
示例#2
0
// CompileFreeSpacing parses a regular expression like Compile,
// but whitespace characters are ignored and # is parsed as the beggining of a line comment.
func CompileFreeSpacing(expr string) (Regexp, error) {
	r, ext, err := syntax.Compile(ignoreCommentsAndSpaces(expr))
	if err != nil {
		return nil, err
	}
	if ext {
		return r, nil
	}
	re, err := regexp.Compile(ignoreComments(ignoreCommentsAndSpaces(expr)))
	return &reg{
		Regexp: re,
	}, err
}