So, I'm facing a curious issue with sed; I have reduced my problem down to the following. Why does
sed -e 's/\"\([^\"]*\)\">/\1/' <<< '["\{">' return ["\{"> instead of [\{? Regex101 suggests that this should work...
So, I'm facing a curious issue with sed; I have reduced my problem down to the following. Why does
sed -e 's/\"\([^\"]*\)\">/\1/' <<< '["\{">' return ["\{"> instead of [\{? Regex101 suggests that this should work...
[^\"] means “any character except \ and "”; so nothing ends up replaced. You’ll get the result you’re after if you remove the backslash from the bracket expression:
sed -e 's/\"\([^"]*\)\">/\1/' <<< '["\{">' In fact you mustn’t escape any of the double quotes here:
sed -e 's/"\([^"]*\)">/\1/' <<< '["\{">' Only a few characters have defined behaviours when escaped in basic regular expressions; all other characters (including double quotes) are undefined.
$ sed -re 's/"([^"]*)">/\1/' <<< '["\{">' -r is the option used by old versions of GNU sed to enable EREs. The equivalent option for newer versions of GNU sed, BSD sed, and all POSIX seds is -E, same as is used in grep to enable EREs.
sedwhen I encountered this curious behavior, which I want to find an explanation for. I don't think what I was messing with is worth explaining here; it'll be quite the tangent imo