How do I make a regular expression for all special characeters in OCaml?

How do I make a regular expression for all special characeters in OCaml?

there should be 32 of them.

Your other questions have been about ocamllex and not so much about OCaml itself. So I’ll assume you want to know how to make a pattern in ocamllex that matches any single character with a character code between 0 and 31.

A rule like this should do what you want:

let special = ['\x00' - '\x1f']

Note that this is exactly the same as your rule for digit except that the range of characters is different.

3 Likes

I want to exclude " and \, how do I do that?

Yes I did mean Ocamlex, I forget they are different since they are so related.

The two characters '"' and '/' are not matched by the special rule as it stands. So it doesn’t make sense to exclude them.

However, to exclude characters from a set you can write a # b , which denotes the characters in set a but not in b.

(Rather than asking a series of brief questions here, I would recommend reading through the documentation. It will be faster in the long run.)

3 Likes