I want to create a pattern for sed, which will find out 'type=""
For this I tried to use the pattern
echo 'aa type="none" stretchChildren="first"' | sed s/'type=".*\?"'/hello/
echo 'aa type="none" stretchChildren="first"' | grep -oP 'type=".*?"'
aa hello stretchChildren="first"
sed doesn't have non-greedy pattern matching, so using
*\? won't work.
If you want to have the same output as grep then use a grouping without the
[^"]+ instead of
sed -r 's/type="[^"]+"/hello/'
] is a group of characters,
^ is a negation, so
[^"] means any character that is not a
For OSX use
-E instead of
-E also works on latest GNU sed, but it is not documented in
--help nor in
man sed so I don't recommend it)