To modify a specific line of a Javascript library, I wrote a shell script using Sed's regex, but I am getting errors because the line of library includes Javascript's Regex, seems Sed thinks it is a part of him. If the line is a normal text, it works well as I expected.
#!/bin/bash
replace() {
if [[ "$OSTYPE" == "darwin"* ]]; then
sed -i "" "s/$1/$2/g" "$3"
else
sed -i "s/$1/$2/g" "$3"
fi
}
# ==========================
# Fix HTML Entities
# ==========================
#
# [']: '
# [>]: >
replace "return str.replace(ampregex, '&').replace(/</g, '<').replace(/\"/g, '"').replace(/\t/g, '	').replace(/\n/g, '
').replace(/\r/g, '
');" \
"return str.replace(ampregex, '&').replace(/</g, '<').replace(/\"/g, '"').replace(/\t/g, '	').replace(/\n/g, '
').replace(/\r/g, '
').replace(/'/g, ''').replace(/>/g, '>');" \
"node_modules/xmlbuilder/lib/XMLStringifier.js"