Bash 3.2 - Array / Regex - IF 3rd member in array ends in 5 digits then do somthing...

Trying to do some control flow parsing based on the index postion of an array member. Here is the pseudo code I am trying to write in (preferably in pure bash) where possible. I am thinking regex with do the trick, but need a little help.


pesudo code 

if [[ array[3] == ENDSINFIVEINTS ]]; then
	do stuff
fi

Thanks in advance.

---------- Post updated at 01:48 AM ---------- Previous update was at 01:43 AM ----------

I found this regex...
but not sure how to incorporate it

 ^\d{5}$ 
#! /bin/bash

x=( 3214 4567 12345 2134 )

echo ${x[2]} | grep -q -E "^[0-9]{5}$"
if [ $? -eq 0 ]
then
    <do_stuff>
fi
grep -E [0-9]{5}$ 

This checks for the last five characters having digits. Note that this will return true if the last 5 or more characters are digits as well.

case ${array[3]} in *[0-9][0-9][0-9][0-9][0-9]) echo OK;; esac

If you really want to use bash's regex matching, to handle differences in bash versions you'd want to use a variable to hold the regex.

#!/bin/bash
re='[[:digit:]]{5}$'
a=(0 1 2 12345 1234)

if [[ ${a[3]} =~ $re ]]; then
  echo true
fi