Browse thread
Str.string_match incorrect
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | Christopher A. Watford <christopher.watford@g...> |
| Subject: | Re: [Caml-list] Str.string_match incorrect |
> > > Then they're simply wrong. The fundamental operation is
> > > to check if a string is in a regular set of strings.
> > > Plainly 'aa' is not in the set { 'a' }.
> >
> > This is a strange notion of right and wrong. The function behaves exactly
> > as it is specified in the documentation.
>
> Huh? I'm really confused. Two people think the documentation
> is correct for the behaviour.
>
> I do not -- Saying
>
> string x is matched by regexp r
>
> means to me the same as
>
> x is a member of the regular set of strings r denotes
>
> and with that interpretation there is no possible doubt that
> the documentation is wrong and should say
>
> matches a prefix of the argument string
>
> in order to describe the behaviour.
>
Going by PCRE's documentation the regex /a/ matches: 'a', 'aa',
'baaaaa', 'nota bene', and any other string with 'a' anywhere inside.
>From OCaml's description of string_match:
val string_match: regexp -> string -> int -> bool
[string_match r s start] tests whether the characters in s starting at
position start match the regular expression r. The first character of
a string has position 0, as usual.
This sounds to me like you're doing the PCRE: /a/
if you say:
Str.string_match (Str.regexp "a") "ab" 0 ;;
And in PCRE /a/ matches "ab" or "aa" or "ba".
/^a/ matches "aa", "ab", but not "ba", and /a$/ matches "aa", "ba",
but not "ab". So as far as I can tell, OCaml's string_match is correct
as the manual describes.
--
Christopher A. Watford
christopher.watford@gmail.com
http://dorm.tunkeymicket.com