regex - Custom character classes in Emacs' regexp -
is possible add own character classes emacs in order use them in regular expressions?
let's say, want add class [[:consonant:]]
matches letters not vowels in order avoid writing [b-df-hj-np-tv-z]
time (and yes, aware shortcut long term want avoid, take simplification of problem).
is possible @ or have use format
or concat
, respectively? if possible, how do that?
an mwe this:
(defun myfun () "finds clusters of 3 or more consonants" (interactive) (if (search-forward-regexp "[b-df-hj-np-tv-z]\\{3,\\}") (message "yepp, here consonant cluster.") )) (defun myfun-1 () "should find clusters of 3 or more consonants." (interactive) (if (search-forward-regexp "[[:consonant:]]\\{3,\\}") (message "yepp, here consonant cluster.") ))
both functions myfun
, myfun-1
should same thing.
one step further i'd know if possible put whole expressions in such "shortcuts",
[[:ending:]] ==> "\\(?:en\\|st\\|t\\|e\\)"
i not believe can this. there similar released in ample-regexp package found here. taken readme example:
(define-arx h-w-rx '((h "hello, ") (w "world"))) ;; -> hello-world-rx (h-w-rx h w) ;; -> "hello, world" (h-w-rx (* h w)) ;; -> "\\(?:hello, world\\)*"
you use define wide range of aliases in 1 big define-arx.
Comments
Post a Comment