Awesome thank you so much, I had missed that the last argument should be a 
pointer to the length and not the length. The working version is:

function my_replace(s::AbstractString, pat::Regex, rep_in)
    offset=0
    Base.compile(pat)
    subject = bytestring(s)
    rep = bytestring(rep_in)
    buffer = Array(UInt8, 256*2)
    re = pat.regex
    length = Ref{Csize_t}(sizeof(buffer))
    rc = ccall((:pcre2_substitute_8, Base.PCRE.PCRE_LIB), Cint,
               (Ptr{Void}, Ptr{UInt8}, Csize_t, Csize_t, Cuint, Ptr{Void}, 
                    Ptr{Void}, Ptr{UInt8}, Csize_t, Ptr{UInt8}, Ref{Csize_t}),
                re, subject, sizeof(subject), offset, pat.match_options, 
pat.match_data,
                    Base.PCRE.MATCH_CONTEXT, rep, sizeof(rep), buffer, length)
    println(rc)
    bytestring(pointer(buffer))
end
my_replace("adsa10as", r"a(\d+)", " \$1 ")

I will probably make a pull to add this functionality to base, if i can get it 
wrapped up nicely.

Reply via email to