Am using rx and am getting
(string-match-p
(rx bos ( "a" "b") eos)
"a")
==> 0
(string-match-p
(rx bos (* "a" "b") eos)
"b")
==> nil
Why is this?
Emacs Stack Exchange is a question and answer site for those using, extending or developing Emacs. It only takes a minute to sign up.
Sign up to join this communityAm using rx and am getting
(string-match-p
(rx bos ( "a" "b") eos)
"a")
==> 0
(string-match-p
(rx bos (* "a" "b") eos)
"b")
==> nil
Why is this?
Not sure what you are trying to do. May be you meant this
(string-match-p (rx bos (or "a" "b") eos) "a")
Note the or operator there.
I usually prefer to write it like this
(string-match-p (rx
(seq
bos
(or "aa" "bb" "cc")
(zero-or-more any)
eos))
"aand")
Note the use of operators seq and or.
I copied what you provided in to *scratch* buffer and I did M-x eval-buffer and I get this
Debugger entered--Lisp error: (error "Bad rx operator ‘\"a\"’")
signal(error ("Bad rx operator ‘\"a\"’"))
error("Bad rx operator `%S'" "a")
rx--translate-form(("a" "b"))
rx--translate(("a" "b"))
mapcar(rx--translate (bos ("a" "b") eos))
rx--translate-seq((bos ("a" "b") eos))
rx--translate-form((seq bos ("a" "b") eos))
rx--translate((seq bos ("a" "b") eos))
rx--to-expr((seq bos ("a" "b") eos))