Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OCaml regex: specify a number of occurrences

Tags:

regex

ocaml

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

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

Thanks.

like image 920
xysun Avatar asked Nov 13 '22 13:11

xysun


1 Answers

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

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

like image 164
snf Avatar answered Nov 15 '22 06:11

snf