简体   繁体   中英

Some special characters are allowed only if they are preceded by an escape character

I want to construct aregular expression (in the style of lex, with a more OCaml-like syntax) for a class of strings, where 4 characters [ , ] , # , ' are allowed only if they are preceded by an escape character ' .

Here are some valid examples:

  • '#Data , abc'#Headers , abc'#Totals'[efg , 123'#Totals']efg , abc , 123

Here are some non-valid examples:

  • #Data , abc#Headers , abc#Totals[efg , 123#Totals]efg , '#Totals[efg

Hope the definition is clear. First, does anyone know how to construct such a regular expression? Second, does anyone know how to construct such aregular expression (in the style of lex, with a more OCaml-like syntax) that can be accepted by ocamllex?

You don't say the accepted strings look like other than with a few examples. Just for concreteness, let's say that lower-case letters and digits are allowed, and the 4 special characters are allowed only if preceded by ' .

This, then, is described by the Kleene closure of a set of 36 one-character strings and 4 two-character strings.

Which looks like this:

 (['a' - 'z' '0' - '9'] | '\'' ['\'' '#' '[' ']'])*

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM