Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
Str.string_match incorrect
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Evan Martin <martine@d...>
Subject: Re: [Caml-list] Str.string_match incorrect
On Wed, Dec 22, 2004 at 02:49:30PM +1100, skaller wrote:
> This looks like a fairly fundamental bug in Str module..
> (so probably I'm missing something ..) 
> This program:
> let m = Str.regexp "a";;
> Str.string_match m "aa" 0;;
[evaluates to true]

This is consistent with the docs, which say:
  [string_match r s start] tests whether the characters in s starting at
  position start match the regular expression r.
and in general with how regular expression systems work.  string_match
corresponds to running your automaton directly and seeing whether you
end up in an accept state, while string_partial_match effectively adds
an extra ".*" to the beginning.
(It's more debatable whether this makes sense.)

To force a match across the entire string, use $:
# Str.string_match (Str.regexp "a$") "aa" 0;;
- : bool = false

Evan Martin