From 754bbf7a25a8dda49b5d08ef0d0443bbf5af0e36 Mon Sep 17 00:00:00 2001 From: Craig Jennings Date: Sun, 7 Apr 2024 13:41:34 -0500 Subject: new repository --- devdocs/elisp/rx-notation.html | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 devdocs/elisp/rx-notation.html (limited to 'devdocs/elisp/rx-notation.html') diff --git a/devdocs/elisp/rx-notation.html b/devdocs/elisp/rx-notation.html new file mode 100644 index 00000000..397812d2 --- /dev/null +++ b/devdocs/elisp/rx-notation.html @@ -0,0 +1,36 @@ +

The rx Structured Regexp Notation

As an alternative to the string-based syntax, Emacs provides the structured rx notation based on Lisp S-expressions. This notation is usually easier to read, write and maintain than regexp strings, and can be indented and commented freely. It requires a conversion into string form since that is what regexp functions expect, but that conversion typically takes place during byte-compilation rather than when the Lisp code using the regexp is run.

Here is an rx regexp22 that matches a block comment in the C programming language:

(rx "/*"                          ; Initial /*
+    (zero-or-more
+     (or (not (any "*"))          ;  Either non-*,
+         (seq "*"                 ;  or * followed by
+              (not (any "/")))))  ;  non-/
+    (one-or-more "*")             ; At least one star,
+    "/")                          ; and the final /
+
+

or, using shorter synonyms and written more compactly,

(rx "/*"
+    (* (| (not "*")
+          (: "*" (not "/"))))
+    (+ "*") "/")
+
+

In conventional string syntax, it would be written

"/\\*\\(?:[^*]\\|\\*[^/]\\)*\\*+/"
+
+

The rx notation is mainly useful in Lisp code; it cannot be used in most interactive situations where a regexp is requested, such as when running query-replace-regexp or in variable customization.

+ + + + + + + + + + + +
+

+ Copyright © 1990-1996, 1998-2022 Free Software Foundation, Inc.
Licensed under the GNU GPL license.
+ https://www.gnu.org/software/emacs/manual/html_node/elisp/Rx-Notation.html +

+
-- cgit v1.2.3