Say I have want to match the string foo.. My regex would be foo\., to escape the special meaning of the . character.
Now say that in my sed command, I use the . as a delimiter.
For a search like, say, cat, this works fine.
echo cat | sed 's.cat.dog.g'
But when I have a literal . in my search string, I run into a problem. I would think, that since the . is my delimiter, my regex foo\. should become foo\\\.. Ideally, the first pass of unescaping would be done by sed to make this into foo\., and then this would get passed along to the regular expression engine.
But instead, it matches cat\\\.
echo 'cat.' | sed 's.cat\\\..dog.g' # cat.
echo 'cat\.' | sed 's.cat\\\..dog.g' # dog
Is there any way to make this work with a literal . when . is used as a delimiter?
I'm asking this question because I want to be able to have a function
function escapeForExtendedSed ($str, $delimiter = "/") { ... }
which can escape correctly depending on what the caller is using as a delimiter.