Skip to main content
Became Hot Network Question
added 84 characters in body
Source Link

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 ([^.]+)?

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
# matches

Is there anything I am missing for the bash =~ operator?

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 ([^.]+)?

deleted 2 characters in body
Source Link

Is the bash operator =~ equivalent to a perl invocation?

filename="test-33.csv"
regex="([^.]+)(-\d{1,5})(\.csv)"

With bash test:

if [[ "$filename" =~ "$regex"$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
# matches

Is there anything I am missing for the bash =~ operator?

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

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
# matches

Is there anything I am missing for the bash =~ operator?

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
# matches

Is there anything I am missing for the bash =~ operator?

Post Undeleted by rellampec
Post Deleted by rellampec
added 33 characters in body
Source Link

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

With perl:

result="$(perl -e '"$filename""if ('$filename' =~ "$regex"'/$regex/) { exit 0;} else { exit 1;} ")"
if [[ result ]]; then echo "it matches"; else echo "doesn't match"; fi
# matches

Is there anything I am missing for the bash =~ operator?

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

With perl:

result="$(perl -e '"$filename" =~ "$regex"')"
if [[ result ]]; then echo "it matches"; else echo "doesn't match"; fi
# matches

Is there anything I am missing for the bash =~ operator?

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

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
# matches

Is there anything I am missing for the bash =~ operator?

Source Link
Loading