unexpected output using regex on sed in unix -
echo "abc123" | sed s/[a-z]*/text/g
for above command output
text1text2text3text
should not texttexttext123
?
it because using quantifier *
matches 0 or more of [a-z]
. first matches abc
, due use of g
(global) mode matches empty text after 1
, 2
, 3
well.
however if tweak regex removing *
using;
echo "abc123" | sed 's/[a-z]/text/g'
then wil get:
texttexttext123
Comments
Post a Comment