Regular expression to match z1 or z2 in Ocaml

How to write regular expressions in ocaml?

How to write a regular expression for "z1" + "z2" (z1 or z2)?

I tried this way, but it gives me errors.

 let p = Str.regexp "("z1")|("z2")";; 
+4
source share
1 answer

If you intend to match double quotes in your input, you should avoid them:

 "(\\"z1\\")\\|(\\"z2\\")" 

And you can reduce the rotation with z1|z2 :

 "(\\"z1\\|z2\\")" 

Otherwise, if double quotes are not part of the input, the pattern should be:

 "(z1\\|z2)" 
+4
source

Source: https://habr.com/ru/post/1384540/


All Articles