ppx_regexp

You can use ppx_regexp in utop…

 1#require "ppx_regexp";;
 2
 3let () =
 4  match%pcre "Date: 1972-01-23  " with
 5  | {|?<date>(?<year>\d{4})-(?<month>\d\d)-(?<day>\d\d)|} ->
 6      Printf.printf "Date found: (%s)\n" date;
 7      Printf.printf "Year: (%s)\n" year;
 8      Printf.printf "Month: (%s)\n" month;
 9      Printf.printf "Day: (%s)\n" day;
10  | _ -> print_string "Date not found\n"
11;;
Date found: (1972-01-23)
Year: (1972)
Month: (01)
Day: (23)
module Ppx_regexp__local : sig val _ppx_regexp_1 : Re.re * Re.markid array end

Building an execuatable

(executable
 (public_name ppx_regex)
 (name main)
 (preprocess (pps ppx_regexp)))
1let () =
2  match%pcre "Date: 1972-01-23  " with
3  | {|?<date>(?<year>\d{4})-(?<month>\d\d)-(?<day>\d\d)|} ->
4      Printf.printf "Date found: (%s)\n" date;
5      Printf.printf "Year: (%s)\n" year;
6      Printf.printf "Month: (%s)\n" month;
7      Printf.printf "Day: (%s)\n" day;
8  | _ -> print_string "Date not found\n"
dune build
dune exec bin/main.exe

The output will be the same as above with utop.