How to properly match the following message id format in a case statement

Posted by hsatterwhite on Stack Overflow See other posts from Stack Overflow or by hsatterwhite
Published on 2012-07-09T15:05:27Z Indexed on 2012/07/09 15:15 UTC
Read the original article Hit count: 217

Filed under:
|
|

I'm trying to get this regex pattern working in a case statement to match a particular type of ID, which could be passed to the script. I need to match the exact number of alphanumeric characters with the dashes to differentiate this message id from anything else, which may be passed to this bash script.

An example of the message id format: c7c3e910-c9d2-71e1-0999-0aec446b0000

#!/bin/bash
until [ -z "$1" ]
 do
    case "$1" in
    "")
        echo "No value passed"
        ;;
    [a-z0-9]\{8\}-[a-z0-9]\{4\}-[a-z0-9]\{4\}-[a-z0-9]\{4\}-[a-z0-9]\{12\})
        echo "Found message ID: $1"
        ;;
    *)
        echo "Server $1"
        ;;
    esac
    shift 
done

© Stack Overflow or respective owner

Related posts about regex

Related posts about bash