matchRegexp return true if a specified regexp matches a string.
(rx interface{}, str interface{})
| 1652 | |
| 1653 | // matchRegexp return true if a specified regexp matches a string. |
| 1654 | func matchRegexp(rx interface{}, str interface{}) bool { |
| 1655 | var r *regexp.Regexp |
| 1656 | if rr, ok := rx.(*regexp.Regexp); ok { |
| 1657 | r = rr |
| 1658 | } else { |
| 1659 | r = regexp.MustCompile(fmt.Sprint(rx)) |
| 1660 | } |
| 1661 | |
| 1662 | switch v := str.(type) { |
| 1663 | case []byte: |
| 1664 | return r.Match(v) |
| 1665 | case string: |
| 1666 | return r.MatchString(v) |
| 1667 | default: |
| 1668 | return r.MatchString(fmt.Sprint(v)) |
| 1669 | } |
| 1670 | |
| 1671 | } |
| 1672 | |
| 1673 | // Regexp asserts that a specified regexp matches a string. |
| 1674 | // |