Typically, I can use the excellent rx macro to create readable regular expressions and make sure that I escape the correct metacharacters.
(rx (any "AZ")) ;; "[AZ]"
However, I cannot figure out how to create shy groups, for example. \(?:AB\) . rx sometimes produces them in its output:
(rx (or "ab" "bc")) ;; "\\(?:ab\\|bc\\)"
but I want to explicitly add them. I can do:
(rx (regexp "\\(?:AB\\)"))
but it defeats the rx point.
In an ideal world, I would like to write:
(rx (shy-group "A"))
I would agree to something like this (none of these works):
;; sadly, `regexp` only accepts literal strings (rx (regexp (format "\\(?:%s\\)" (rx WHATEVER)))) ;; also unfortunate, `eval` quotes the string it given (rx (eval (format "\\(?:%s\\)" (rx WHATEVER))))
How to create regular expressions with shy groups using rx ?
source share