Is the bash operator =~
equivalent to a perl
invocation?
filename="test-33.csv"
regex="([^.]+)(-\d{1,5})(\.csv)"
With bash test:
if [[ "$filename" =~ $regex ]]; then echo "it matches"; else echo "doesn't match"; fi
# doesn't match
if [[ "$filename" =~ ([^.]+)(-\d{1,5})(\.csv) ]]; then echo "matches"; else echo "doesn't match"; fi
# doesn't match
With perl
:
result="$(perl -e "if ('$filename' =~ /$regex/) { exit 0;} else { exit 1;} ")"
if [[ result ]]; then echo "it matches"; else echo "doesn't match"; fi
# it matches
Is there anything I am missing for the bash =~
operator? Does this have something to do with the greedy vs non-greedy iterator ([^.]+
)?