gpt4 book ai didi

regex - OCaml 中 "not belonging to"的正则表达式

转载 作者:行者123 更新时间:2023-12-04 18:15:38 28 4
gpt4 key购买 nike

我想定义non-line-termination-character = <any character other than %x000D / %x000A>lexer.mll .我试过let non_line_termination_character = [^('\x0D' '\x0A')] ,但它给了我一个语法错误。

我认为 let non_line_termination_character = [^'\x0D'] intersect [^'\x0A']可以,但我不知道如何表达intersect .

有人可以帮忙吗?

PS:规则在12.2.4 Regular expressions的:http://caml.inria.fr/pub/docs/manual-ocaml/manual026.html

最佳答案

ocamllex 中字符集的语法不允许使用括号。以下对我有用:

let non_line_termination_character = [^ '\x0d' '\x0a' ]

ocamllex 中没有用于相交正则表达式的通用运算符。但是对于两个字符集 a 和 b 你可以写 a # (a # b) .
let nona = [^ 'a']
let nonb = [^ 'b']
let nonab = nona # (nona # nonb)

(奇怪的是,我的测试表明这适用于我尝试的每个字符集,但它对于非 CR 和非 LF 的特定示例失败。它实际上看起来像一个错误。但也许我遗漏了一些明显的东西。)

关于regex - OCaml 中 "not belonging to"的正则表达式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11770567/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com