(Another) Correct (?) regex not understood by sed

Viewed 52

According to https://regex101.com/r/KVQPk0/1, the following regex (in my real use case, I need the group for back references):

<latex>\$([^$]*)\$<\/latex>

(full) matches the string <latex>$\rightarrow$</latex>, but this seems to not be understood by sed. Indeed:

echo "<latex>$\\\rightarrow$</latex>" | sed -E -e "#<latex>\$([^$]*)\$</latex>#\:math\:\&$1@#d"

(which should return an empty string) verbatim returns:

<latex>$\rightarrow$</latex>

What is the regex that matches <latex>$\rightarrow$</latex> from sed's point of view?

Edit

I mixed up my tests and the command which should return nothing (AFAIU) is:

echo "<latex>$\\\rightarrow$</latex>" | sed -E -e "#<latex>\$([^$]*)\$</latex>#d"

Edit 2

My shell is zsh.

1 Answers

Thanks to the comments, here is the regex that matches <latex>$\rightarrow$</latex> from sed's point of view:

printf '%s\n' '<latex>$\rightarrow$</latex>' | sed -E -e '/<latex>\$([^$]*)\$<\/latex>/d'
Related