Given a string of pipe-separated values (call it $psv
), I want to be able to split by those pipes and populate an array. However, the string can also contain escaped pipes (\|
) and escaped escapes (\\
), both of which are to be considered mere literals. I have a couple solutions for this problem in mind:
- Replace both escape sequences with some random strings not-otherwise found in the
$psv
,split(/\|/, $psv)
, replace back original characters - Loop through
$psv
, character-by-character
And I think both of those would work. But for a maximum dopamine flood, I'd like to just do this with a single split()
call and nothing else. So is there a regular expression for this?