Wednesday, 21 August 2013

regex: plus sign vs asterisk

regex: plus sign vs asterisk

The asterisk or star tells the engine to attempt to match the preceding
token zero or more times. The plus tells the engine to attempt to match
the preceding token once or more.
Based on the definition, I was wondering why the plus sign returns more
matches than the asterisk sign.
echo "ABC ddd kkk DDD" | grep -Eo "[A-Z]+"
returns
ABC DDD
echo "ABC ddd kkk DDD" | grep -Eo "[A-Z]*"
returns ABC

No comments:

Post a Comment