Test whether a given string matches a given regular expression
(do-regex-match str pat opts) → (mv error-msg whole substrs)
Intended for use in the dynamically compiled case.
As examples:
(do-regex-match "cdeAbfdEfDeghIj" "cdeabfdefdeghij" (parse-options 'fixed ; type nil ; not strict-paren nil ; not strict-brace nil ; not strict-repeat t ; case-insensitive ))
returns (mv nil "cdeAbfdEfDeghIj" nil),
(do-regex-match "cdeAbfdEfDeghIj" "ab([def]*)\1([gh])" (parse-options 'fixed nil nil nil t))
returns (mv nil nil nil), and
(do-regex-match "cdeAbfdEfDeghIj" "ab([def]*)\1([gh])" (parse-options 'ere nil nil nil t))
returns (mv nil "AbfdEfDeg" ("fdE" "g")).
Function:
(defun do-regex-match (str pat opts) (declare (xargs :guard (and (stringp str) (stringp pat) (parse-opts-p opts)))) (let ((__function__ 'do-regex-match)) (declare (ignorable __function__)) (b* ((str (mbe :logic (if (stringp str) str "") :exec str)) (pat (mbe :logic (if (stringp pat) pat "") :exec pat)) (pat (if (parse-options-case-insensitive opts) (str::downcase-string pat) pat)) (regex (regex-do-parse pat opts)) ((when (stringp regex)) (mv regex nil nil)) ((mv whole substrs) (do-regex-match-precomp str regex opts))) (mv nil whole substrs))))
Theorem:
(defthm return-type-of-do-regex-match.error-msg (b* (((mv ?error-msg ?whole ?substrs) (do-regex-match str pat opts))) (or (stringp error-msg) (not error-msg))) :rule-classes :type-prescription)
Theorem:
(defthm return-type-of-do-regex-match.whole (b* (((mv ?error-msg ?whole ?substrs) (do-regex-match str pat opts))) (or (stringp whole) (not whole))) :rule-classes :type-prescription)
Theorem:
(defthm true-listp-of-do-regex-match.substrs (b* (((mv ?error-msg ?whole ?substrs) (do-regex-match str pat opts))) (true-listp substrs)) :rule-classes :type-prescription)
Theorem:
(defthm string-or-nil-listp-of-do-regex-match-substrs (string-or-nil-listp (mv-nth 2 (do-regex-match str regex opts))))