matchRegexp return true if a specified regexp matches a string.
(rx interface{}, str interface{})
| 1702 | |
| 1703 | // matchRegexp return true if a specified regexp matches a string. |
| 1704 | func matchRegexp(rx interface{}, str interface{}) bool { |
| 1705 | var r *regexp.Regexp |
| 1706 | if rr, ok := rx.(*regexp.Regexp); ok { |
| 1707 | r = rr |
| 1708 | } else { |
| 1709 | r = regexp.MustCompile(fmt.Sprint(rx)) |
| 1710 | } |
| 1711 | |
| 1712 | switch v := str.(type) { |
| 1713 | case []byte: |
| 1714 | return r.Match(v) |
| 1715 | case string: |
| 1716 | return r.MatchString(v) |
| 1717 | default: |
| 1718 | return r.MatchString(fmt.Sprint(v)) |
| 1719 | } |
| 1720 | } |
| 1721 | |
| 1722 | // Regexp asserts that a specified regexp matches a string. |
| 1723 | // |