xysun
xysun

Reputation: 2015

OCaml regex: specify a number of occurrences

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.

Upvotes: 5

Views: 755

Answers (1)

snf
snf

Reputation: 3077

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 .

Upvotes: 1

Related Questions