OCaml regex: specify the number of occurrences

In OCaml, how can I specify the number of occurrences for a template in regex? I went through the Str module and cannot find the equivalent for the quantifier {n} .

For example, if I want to specify the template "Year", i.e. exactly 4 digits, is there any way other than executing "[0-9][0-9][0-9][0-9]" ?

Thanks.

+4
source share
1 answer

Comment extension rgrinberg, ocaml-re ( https://github.com/ocaml/ocaml-re ) supports Perl, PCRE and Emacs modes, which support the {m, n} quantifier.

Link to a test showing that it supports it (using perl mode): https://github.com/ocaml/ocaml-re/blob/master/lib_test/test_perl.ml#L80 .

+1
source

All Articles