0

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?

2

1 Answer 1

0

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))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.