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

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

java - Digest auth with Spring Security using javaconfig -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -