Match returns true if input matches the compiled regular expression in m. It sets values on the replacer repl associated with capture groups, using the given scope (namespace).
(input string, repl *caddy.Replacer)
| 197 | // associated with capture groups, using the given scope |
| 198 | // (namespace). |
| 199 | func (mre *MatchRegexp) Match(input string, repl *caddy.Replacer) bool { |
| 200 | matches := mre.compiled.FindStringSubmatch(input) |
| 201 | if matches == nil { |
| 202 | return false |
| 203 | } |
| 204 | |
| 205 | // save all capture groups, first by index |
| 206 | for i, match := range matches { |
| 207 | keySuffix := "." + strconv.Itoa(i) |
| 208 | if mre.Name != "" { |
| 209 | repl.Set(regexpPlaceholderPrefix+"."+mre.Name+keySuffix, match) |
| 210 | } |
| 211 | repl.Set(regexpPlaceholderPrefix+keySuffix, match) |
| 212 | } |
| 213 | |
| 214 | // then by name |
| 215 | for i, name := range mre.compiled.SubexpNames() { |
| 216 | // skip the first element (the full match), and empty names |
| 217 | if i == 0 || name == "" { |
| 218 | continue |
| 219 | } |
| 220 | |
| 221 | keySuffix := "." + name |
| 222 | if mre.Name != "" { |
| 223 | repl.Set(regexpPlaceholderPrefix+"."+mre.Name+keySuffix, matches[i]) |
| 224 | } |
| 225 | repl.Set(regexpPlaceholderPrefix+keySuffix, matches[i]) |
| 226 | } |
| 227 | |
| 228 | return true |
| 229 | } |
| 230 | |
| 231 | // UnmarshalCaddyfile implements caddyfile.Unmarshaler. |
| 232 | func (mre *MatchRegexp) UnmarshalCaddyfile(d *caddyfile.Dispenser) error { |