In cl-ppcre, how can I find out the number of register groups in a regular expression?

Using cl-ppcre, I want to find out the number of register groups in a regular expression without doing any match. Is this possible and how?

+3
source share
1 answer

If you have a regular expression as a string, you can use cl-ppcre:parse-stringto convert it to sexp, which you can check for cases :REGISTERlike

(count :register (alexandria:flatten (ppcre:parse-string "^\\d (\\S+|(x|y))")))

If it has already been created using create-scanner, I don’t think you have many options; this object is an opaque closure.

+5
source

Source: https://habr.com/ru/post/1774153/


All Articles