Source file utils_regex.ml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
type t = Re.Pcre.regexp
let of_string string = Re.Pcre.regexp string
let test regexp string = Re.Pcre.pmatch ~rex:regexp string
let regexp text =
let ( let* ) = Option.bind in
let = Array.to_list (Re.Pcre.extract ~rex:regexp text) in
let* =
try Some (List.tl extracts) with
| _ -> None
in
try Some (List.hd extracts) with
| _ -> None
;;
module Re = Re