Questions tagged [rx]
25 questions
16
votes
1 answer
How do I create a dynamic regexp with rx?
I want to use rx to create regular expressions with runtime values.
Currently, I'm doing this:
(setq strings '("foo" "bar" "baz"))
(eval `(rx symbol-start (or ,@strings) symbol-end))
However, I'd rather avoid using eval. I've found rx-to-string,…

Wilfred Hughes
- 6,890
- 2
- 29
- 59
7
votes
1 answer
Is there any principal difference between "A-Z" and upper?
I just want to make sure I understood this correctly.
(rx (one-or-more (any upper lower)))
is equal to
(rx (one-or-more (any "A-Z" "a-z")))
Correct?

serghei
- 272
- 3
- 15
5
votes
4 answers
Is there a way to search/replace with regexps interactively using rx syntax?
I really like rx but I can't use it interactively.
Has someone already tried to extend isearch to support rx syntax?

knarf
- 313
- 2
- 8
4
votes
1 answer
Regexp to parse Hy errors for Flycheck
I'm trying to write a Flycheck checker definition based on Hy, using the API here. As part of that, I have to define a pattern for error matching. Now, Hy gives quite a large error spew, for example:
Traceback (most recent call last):
File…

Koz Ross
- 425
- 3
- 13
3
votes
2 answers
How do I use not in rx-to-string?
I just started working with rx and was able to achieve the opposite of the regex I wanted:
(rx-to-string `(: (or
(: line-start (not ,comment-start))
(: line-start (zero-or-more whitespace) line-end))))
Unfortunately, notting this regex was not…

The Unfun Cat
- 2,393
- 16
- 32
2
votes
1 answer
Why do rx-let definitions not work inside of pcase?
I am using pattern matching in Emacs Lisp with pcase. I would like to simplify the rx expressions I am using by binding common pattern with rx-let. However, it seems like if you use rx by itself the substitution works as expected. However, if rx is…
2
votes
1 answer
Trouble while using string-match with rx expression
I'm trying to write a function that takes a string and returns non-nil if it's the word do not followed by the character :. Something like this:
(string-match (rx "do[^:]") input)
but I get the following result:
(string-match (rx "do[^:]") "do") ;;…

riekes
- 23
- 3
2
votes
2 answers
Rx: Skip commented out lines
I'm trying to make an expression that would match the text foo if it's not on a commented out line.
;; foo ; <= not this
bar ; <= not this
foo ; <= this
Now rx.el can exclude character syntax classes, like:
(rx
(not (syntax comment-start))
…

yPhil
- 963
- 5
- 22
2
votes
1 answer
How to use re-builder with rx special forms?
I opened re-builder and changed its syntax to "rx". My target buffer has plenty of digits and (rx (and "4")) highlights a lot of 4s, however, (rx (and digit)) is apparently valid but matches nothing on the same target buffer! So far I only got…

luntain
- 131
- 2
1
vote
1 answer
Can you split rx into multiple variables and concatenate the evaluation
I have a really useful regex for extracting DCOs:
(defvar my-dco-tag-re
(rx (: bol (zero-or-more (in blank)) ; fresh line
(any "RSTA") (one-or-more (in alpha "-")) "-by: " ; tag
(one-or-more (in alpha blank…

stsquad
- 4,626
- 28
- 45
1
vote
2 answers
Symbol's function definition is void: rx-let
Whenever I try to use elpy, or even just fontlock (with elpy disabled) in a python file, I get the error that rx-let is void.
This is what I got from --debug-init:
Debugger entered--Lisp error: (void-function rx-let)
(rx-let ((block-start (seq…

Benjamin Philip
- 59
- 4
1
vote
1 answer
Regular expressions tool example explanation
Reading the section regular expressions in EmacsWiki appears this:
You can use a tool to construct regexps. For example, you can use ‘rx’ like this:
(rx (or (and "\*" (*? anything) "*/") (and "//" (*? anything) eol)))
To produce this regexp (which…

nephewtom
- 2,219
- 17
- 29
1
vote
2 answers
`rx` form, that is partially compiled, partially variable?
Is it possible to obtain an (rx ...) form, that is expanded at compile time for performance, but partially variable?
rx-to-string may be slow
For instance I want an expression that behaves equivalent to
(rx-to-string `(: "PREFIX"
…

kdb
- 1,561
- 12
- 21
1
vote
3 answers
Highlight a comma-separated list by using rx macro
I want to create font locking for string like:
interface Foo extends B, C, D, E {};
And I can't understand why my regexp rule doesn't work for font locking:
(defvar my-font-lock-keywords
`(
;; Some code is omitted for brevity
;; ...
…

serghei
- 272
- 3
- 15
1
vote
2 answers
Does rx macro work with underscore in character classes
I'm a little confused by the fact that underscore does not shown in the character class.
ELISP> (require 'rx)
rx
ELISP> (rx (any "A-Z" "_"))
"[A-Z_]"
ELISP> (rx (any "A-z" "_"))
"[A-z]"
Expected result is "[A-z_]" but actual is "[A-z]".
But the…

serghei
- 272
- 3
- 15