From 83ea247e7a729200c93c1d3e95fe1b90e5be52b8 Mon Sep 17 00:00:00 2001 From: Viet Ho Date: Thu, 8 Aug 2024 07:35:21 -0500 Subject: [PATCH] added new method `MatchStringSafe` --- regexp.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/regexp.go b/regexp.go index a7ddbaf..800c425 100644 --- a/regexp.go +++ b/regexp.go @@ -240,6 +240,16 @@ func (re *Regexp) MatchString(s string) (bool, error) { return m != nil, nil } +// MatchStringSafe returns true if the string matches the regex. +// It ignores any errors and simply returns false if an error occurs. +func (re *Regexp) MatchStringSafe(s string) bool { + m, err := re.run(true, -1, getRunes(s)) + if err != nil { + return false + } + return m != nil +} + func (re *Regexp) getRunesAndStart(s string, startAt int) ([]rune, int) { if startAt < 0 { if re.RightToLeft() {