Version française
Home     About     Download     Resources     Contact us    
Browse thread
Labels and operators
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Ken Wakita <wakita@i...>
Subject: Re: Labels and operators

Hello.

I tried the same with the Str module.  Except for the parenthesis, it
seems ok to me.

Ken

let pmatch s ~pat ?(direction = `forward) ?(pos = 0) () =
  match direction with
    `forward -> Str.search_forward ~pat s ~pos
  | `backward -> Str.search_backward ~pat s ~pos

let (=~) s regexp = pmatch s (Str.regexp regexp)

# ("Hello world!" =~ "[a-z]+") ();;
- : int = 1
# ("Hello world!" =~ "[A-Za-z]+") ();;
- : int = 0
# ("Hello world!" =~ "[A-Za-z]+") ~direction: `backward ~pos: 12 ();;
- : int = 10
# ("Hello world!" =~ "[A-Za-z]+") ~direction: `backward ~pos: 10 ();;
- : int = 10
#