1

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

1 Answer 1

2

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

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.