On 13-12-2010, OGrandeDiEnne <[email protected]> wrote:
> Hello people,
> i need to make a small function that parses a string and generate some
> values accordingly. I was thinking something like:
>
> fun s = match  s with
>| "aaaa" -> ValueA
>| "bbbb" -> ValueB
>
> one of this strings is variable and contains substring/subvalues. I
> can recognize it because it's wrapped in graph parenthesis: like
> "{ foo=aaaa , bar=bbbb }".
>
> It would be nice if the pattern matching could work as a regular
> expression matching like
>
>| "{" something "}" -> ...computation of something
>
>
> Is it possible ? Which is the easiest way to recursively match a
> string ?
>

What you want is called mikmatch:
http://martin.jambon.free.fr/mikmatch-manual.html

For example

match s with
| RE "{" ("a"+ | "b"+ as intern) "}" ->
    prerr_endline intern

It uses Pcre.

Regards,
Sylvain Le Gall

-- 
You received this message because you are subscribed to the Google Groups 
"ocaml-developer" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/ocaml-developer?hl=en
For other OCaml forums, see http://caml.inria.fr/resources/forums.en.html

Reply via email to