Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

LoadError: PCRE compilation error: lookbehind assertion is not fixed length

Tags:

regex

pcre

julia

When I try to write a parser in julia that uses a lookbehind pattern, it throws an PCRE compilation error.

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

Can somebody explain what I'm doing wrong?

like image 866
Jonas Avatar asked Oct 28 '25 14:10

Jonas


1 Answers

Julia uses Perl Compatible Regular Expressions (pcre), and as stated in the pcre documentation:

Each top-level branch of a lookbehind must be of a fixed length.

Meaning you can't use operators like * or + in a lookbehind pattern.

So you'd have to figure out a pattern that doesn't use them. In your case the following might work:

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")
like image 83
Jonas Avatar answered Oct 30 '25 08:10

Jonas



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!