载入错误:PCRE编译错误:向后查找断言不是固定长度。

4

我尝试在Julia中编写使用回顾后发模式的解析器时,它会抛出PCRE编译错误

function parser(str::String)
    a = match(r"^[a-zA-Z]*_[0-9]", str)
    b = match(r"(?<=[a-zA-Z]*_[0-9]_)[a-zA-Z]", str)
    a.match, b.match
end

parser("Block_1_Fertilized_station_C_position_23 KA1F.C.23")
# LoadError: PCRE compilation error: lookbehind assertion is not fixed length at offset 0

能否有人解释一下我做错了什么?

1个回答

4

Julia使用Perl兼容正则表达式(pcre),如在pcre文档中所述:

每个顶级回溯分支必须具有固定长度。

这意味着您不能在回溯模式中使用像*+这样的操作符。

因此,您需要找出一个不使用它们的模式。在您的情况下,以下内容可能有效:

function parser(str::String)
    a = match(r"^[a-zA-Z]*_[0-9]", str)
    b = match(r"(?<=_[0-9]_)[a-zA-Z]*", str)
    a.match, b.match
end

parser("Block_1_Fertilized_station_C_position_23 KA1F.C.23")
# ("Block_1", "Fertilized")

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接