(rx bos (1+ (in "0-2")) eos)
evaluates to "\\`[0-2]+\\'"
, so I expected these two functions to be equivalent:
(defun with-rx (s)
(pcase s
((rx bos (1+ (in "0-2")) eos) "matched")
(t "not matched")))
(defun with-regex (s)
(pcase s
("\\`[0-2]+\\'" "matched")
(t "not matched")))
However, it seems that pcase
treats the rx
form as a real regexp in the first case and the string as a simple string in the second case:
ELISP> (equal (rx bos (1+ (in "0-2")) eos) "\\`[0-2]+\\'")
t
ELISP> (with-rx "01210")
"matched"
ELISP> (with-regex "01210")
"not matched"
How come in the rx
case, pcase
is smart enough to know that it should treat the rx
form as a regex?