On 29/09/14 22:04, Tom Ridge wrote:
> I am trying to use the Str module to match regular expressions. I want to
> return the longest match.[...] I don't want the order of
> the alternatives to matter. What am I doing wrong?
Nothing: it's just that Str has first-match semantics, not longest-match.
> What can I do to match the longest substring?
In this particular example, you can sort the string patterns in
decreasing lexicographic order before putting them in ...|...|...
In more general case, you might have more luck with other regexp
libraries (e.g. PCRE or Vouillon's RE, but I didn't check whether they
implement longest match).
Hope this helps,
- Xavier Leroy
--
Caml-list mailing list. Subscription management and archives:
https://sympa.inria.fr/sympa/arc/caml-list
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs