anyone can explain this?

why the case 2 will happen ? , ' should stop the history substitution ,shouldn't it?
case 1

# echo "123"|sed '/123/!d'
123

case 2

# echo "123
> 456
> 1
> "|sed '/123/!d'
-bash: !d': event not found

case 3

# echo "123
> 456
> 12
> "|sed '/123/'\!d
123
# bash --version
GNU bash, version 3.2.25(1)-release (x86_64-redhat-linux-gnu)
Copyright (C) 2005 Free Software Foundation, Inc.

# sed --version
GNU sed version 4.1.5
Copyright (C) 2003 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE,to the extent permitted by law.

No, it doesn't.

I find the ! history expanson annoying and intrusive; I always disable it in my .bashrc file with:

histchars=

The exclamation mark is a printing character, and the ! key should print !.