My 2 cents after looking into the code.
The input buffer (buf) is clipped at 4096 characters, and this quite easily may result in the appearance of a composite UTF8 character being cut off at the end. Thus, since regex has its UTF8 glasses solidly stuck on, one can't apply it to buf.
So I thought that, instead of immediately cleaning the parse result when extracting lines, one could let partial always be its last element, chopped off (or cleaning lines afterwards). That would keep to the same functionality and avoid using regex on buf.
EDIT: actually, my "quite easily" assertion might be wrong... but the fix is still vaild...
EDIT 2: the more I study this the more I realize how wrong I were. As far as I can see, that particular error code only arises in quite particular cases: such as functions first and rest, and implicit string indexing. The latter would be the candidate cause here, except that the regex expressions don't have implicit indexing.