14wml
14wml

Reputation: 4166

Regex not matching string (OCaml Str module)

I have this preword and regex:

let regex = Str.regexp "\\([A-Za-z0-9]\\.*[A-Za-z0-9]\\)";;
let s = "--O--c-a-l**9+===";;

My regex is matching for a string that begins with a letter or number, has 0 to as many character in between, and ends with a letter or number. So the substring "O--c-a-l**9+" should match.

But when I see if my preword matches my regex, it keeps saying it doesn't match

Str.search_forward regex s 0;;
Exception: Not_found.

And I'm not sure what I'm missing in my regex for it to not match my string.


Str documentation

enter image description here enter image description here

Upvotes: 1

Views: 448

Answers (1)

sepp2k
sepp2k

Reputation: 370172

You escaped the ., so it will only match literal dots. To match any character, remove the \\.

Upvotes: 2

Related Questions