diff --git a/doc/lispref/searching.texi b/doc/lispref/searching.texi index 3d7ea932863..5f4509a8b43 100644 --- a/doc/lispref/searching.texi +++ b/doc/lispref/searching.texi @@ -1080,7 +1080,10 @@ Corresponding string regexp: @samp{@var{A}@var{B}@dots{}} @cindex @code{or} in rx @itemx @code{(| @var{rx}@dots{})} @cindex @code{|} in rx -Match exactly one of the @var{rx}s, trying from left to right. +Match exactly one of the @var{rx}s. +If all arguments are string literals, the longest possible match +will always be used. Otherwise, either the longest match or the +first (in left-to-right order) will be used. Without arguments, the expression will not match anything at all.@* Corresponding string regexp: @samp{@var{A}\|@var{B}\|@dots{}}. diff --git a/lisp/emacs-lisp/rx.el b/lisp/emacs-lisp/rx.el index 03af053c91e..b4cab5715da 100644 --- a/lisp/emacs-lisp/rx.el +++ b/lisp/emacs-lisp/rx.el @@ -290,7 +290,7 @@ Return (REGEXP . PRECEDENCE)." ((null (cdr body)) ; Single item. (rx--translate (car body))) ((rx--every #'stringp body) ; All strings. - (cons (list (regexp-opt body nil t)) + (cons (list (regexp-opt body nil)) t)) ((rx--every #'rx--charset-p body) ; All charsets. (rx--translate-union nil body)) diff --git a/test/lisp/emacs-lisp/rx-tests.el b/test/lisp/emacs-lisp/rx-tests.el index e19e626527b..a6c172adfe7 100644 --- a/test/lisp/emacs-lisp/rx-tests.el +++ b/test/lisp/emacs-lisp/rx-tests.el @@ -43,7 +43,7 @@ (should (equal (rx (or "ab" (| "c" nonl) "de")) "ab\\|c\\|.\\|de")) (should (equal (rx (or "ab" "abc" "a")) - "\\(?:ab\\|abc\\|a\\)")) + "\\(?:a\\(?:bc?\\)?\\)")) (should (equal (rx (| nonl "a") (| "b" blank)) "\\(?:.\\|a\\)\\(?:b\\|[[:blank:]]\\)")) (should (equal (rx (|))