regexpPrefix returns the prefix of the provided regular expression (if one exists) only if the regular expression matches the beginning of a string.
(s string)
| 186 | // regexpPrefix returns the prefix of the provided regular expression (if one |
| 187 | // exists) only if the regular expression matches the beginning of a string. |
| 188 | func regexpPrefix(s string) string { |
| 189 | re, err := syntax.Parse(s, syntax.Perl) |
| 190 | if err != nil { |
| 191 | return "" |
| 192 | } |
| 193 | re = re.Simplify() |
| 194 | if re.Op == syntax.OpConcat && |
| 195 | len(re.Sub) >= 2 && |
| 196 | re.Sub[0].Op == syntax.OpBeginText && |
| 197 | re.Sub[1].Op == syntax.OpLiteral { |
| 198 | return string(re.Sub[1].Rune) |
| 199 | } |
| 200 | return "" |
| 201 | } |
| 202 | |
| 203 | func regexpMaxPrefix(s string) string { |
| 204 | b := []byte(s) |
no test coverage detected