I'm making a function with a replacement of strings using regular expressions in a secure way, without possibility to inject characters, and without renouncing the use of regular expressions:
#! /bin/sh
stringer()
{
pattern="${1}"
replace="${2}"
printf '%s\n' "examp/e w\\th sed: " | sed "s/${pattern}/${replace}/g"
}
stringer "\\/" "l"
So far so good, but if I use:
stringer "/" "l"
it would result in a sed error, about this I know that the input parameters can be escaped, but then it wouldn't can be used with regular expressions, and I want to be able to use it with regex, any suggestions with or without sed but without extensions for posix-compliant way?