'How to replace two strings as literals with sed?

I want to replace content: [], with content: ['./src/**/*.{js,jsx,ts,tsx}'], using sed and I'm trying this command:

echo content: [], | sed -e s/content: \[\]/content: \['\.\/src\/\*\*\/\*\.\{js,jsx,ts,tsx}']/

But I get this error:

zsh: no matches found: [],
sed: 1: "s/content:
": unterminated substitute pattern

Ideally I want to treat the two sides in the sed command as literal strings but apparently no matter what, it treats different characters as regular expression parts.

sed


Solution 1:[1]

You'll need to wrap both the echo and sed command in quotes ("") so ZSH won't expand them:

echo 'content: [],' | sed -e "s/content: \[\]/content: \['\.\/src\/\*\*\/\*\.\{js,jsx,ts,tsx}']/"
content: ['./src/**/*.{js,jsx,ts,tsx}'],

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 0stone0