As you can see difference is use of greedy pattern .*
in second regex after "
without space.
Reason why it is behaving differently because there is a double quote after no_but_why=
as well and .*
being a greedy pattern is matching until last "
before />
in second regex.
In your first regex "\(.*\)"
is matching only "bob3"
because there is a space after this which makes regex engine prevent .*
matching till last double quote in input.
To avoid this situation you should be using negated character class instead of greedy matching.
Consider these sed command examples:
sed -e 's/.*value="\([^"]*\)" .*/\1/' <<< "$abcs"
bob3
sed -e 's/.*value="\([^"]*\)".*/\1/' <<< "$abcs"
bob3
Now you can see both command are producing same output bob3
because negated character class [^"]*
will match until it gets next "
not till the very last "
in input as the case with .*
.