ocaml-re
ocaml-re copied to clipboard
Substring matching + lookaround weird interaction
Substring matches are able to "peek" outside of substrings when lookaround assertions are start/begin of the re. Here's an example of what I mean:
utop[19]> let re = Re.(compile @@ seq [bol ; str "xxx"]);;
val re : Re.re = <abstr>
utop[20]> Re.execp ~pos:1 ~len:3 re "yxxx";;
- : bool = false
utop[21]> Re.execp ~pos:1 ~len:3 re "\nxxx";;
- : bool = true
This means that there's no way for the user to independently match a substring. Not really broken but counter intuitive IMHO.
cc @Drup
That's what we want, for instance if we want to split a string at each beginning of line.
But indeed, there is no way to tell Re to match without look outside a substring, which might be convenient when using a string as a buffer.