I am usign a flatfile database with a delimiter character, the delimiter character is defined by the user and stored in $this->_config->delimiter(). I want to run Regexp on the input string to safely escape both the delimiter character and the \ character e.g.
// $this->_config->delimiter() = "|"
$input = "the quick | brown \ fox jumped";
// function returning output here
$output = "the quick \| brown \\ fox jumped";
If you know a better/faster way of doing this without regexp I am open to that aswell.
Is it possible to do this with a variable in the regex?
You don’t need a regex. Do: