I am trying to replace the image tag for all URLs except the URL with image bar
. But, it says that the regular expression is invalid.
Checking just the regular expression (image:(?!.*bar).*:).*
on regex101.com looked fine. The error comes while replacing the 2nd part of the sed expression with the group (image:(?!.*bar).*:)
.
$ echo '
image: mydomain/subdomain/foo:old_tag
image: mydomain/subdomain/bar:dont_update_me_tag
image: mydomain/subdomain/baz:old_tag
' | sed --regexp-extended "s|(image:(?!.*bar).*:).*|\1new_tag|g"
sed: -e expression #1, char 36: Invalid preceding regular expression
The expected end result is:
image: mydomain/subdomain/foo:new_tag
image: mydomain/subdomain/bar:dont_update_me_tag
image: mydomain/subdomain/baz:new_tag
Explanation of the regex (image:(?!.*bar).*:).*
Search for all lines containing image:.*:.*
except those containingimage:.*bar