Pattern matching notation

Hello,

I want to match this patterns
IS01ORA
IS02ORA
...
...
IS08ORA

With that :

IS[1-8]ORA

But it doesn't work, can you correct it ?

Thanks

IS0[1-8]ORA

[1-8] just matches a single character. To match the '0', you have to explicitly include it.

I have forgotten the zero, i meant

IS0[1-8]ORA

But the matching doesn't work ?

Thanks for your help.

Can you show your complete command?

In magenta

#!/bin/bash
#########################################################################
valid() {
case "$1" in
        [E,F,Q,P][A,C,S][A,I,V,P][D,R,T,V]) ;;
        *) return 1 ;;
        esac

        case "$2" in
        [PU][IPS][AGS][1-8]) ;;
        IS0[1-8]ORA ;;
        *) return 1 ;;
        esac

        case "$3" in
        [0-1][0-9]) ;;
        2[0-3]) ;;
        *) return 1 ;;
        esac

        case "$4" in
        [0-5][0-9]) ;;
        *) return 1 ;;
        esac

        case "$5" in
        server) ;;
        exploitation) ;;
        *) return 1 ;;
        esac

        OLDIFS="$IFS"
        IFS="-"
               set -- $6 # $6=YYYY, $2=MM, $3=DD
        IFS="$OLDIFS"

        case "$1" in
        [2-9][0-9][0-9][0-9]) ;;
        *) return 1 ;;
        esac

        case "$2" in
        0[1-9]) ;;
        1[0-2]) ;;
        *) return 1 ;;
        esac

        case "$3" in
        0[1-9]) ;;
        [1-2][0-9]) ;;
        3[0-1]) ;;
        *) return 1 ;;
        esac

        return 0
}
process() {
echo "$1 $2 $3 $4 $5 $6"
}

        if ! valid $1 $2 $3 $4 $5 $6 # Ignore invalid lines
        then
                echo "$1 $2 $3 $4 $5 $6 is invalid"
        else
        process $1 $2 $3 $4 $5 $6
fi

You omitted the ")" after the pattern.

On an unrelated note, in case you are not aware, the following can be re-written ...

... by combining pattern alternatives with "|".

        case $3 in
        0[1-9] | [1-2][0-9] | 3[0-1]) ;;
        *) return 1 ;;
        esac

Note that I did not double-quote $3. There's nothing wrong with doing so, but it's not necessary. Double quotes only protect against field splitting and pathname expansion (file globbing), neither of which is performed on the word which follows "case".

Regards,
Alister

Thank you for yours advices.
But look with this magenta pattern. it doesn't work.
Have you an idea why ?

#!/bin/bash
#########################################################################
valid() {
case "$1" in
        [E,F,Q,P][A,C,S][A,I,V,P][D,R,T,V]) ;;
        *) return 1 ;;
        esac

        case "$2" in
        [PU][IPS][AGS][1-8]) ;;
        ISO[9-10]ORA) ;;
        *) return 1 ;;
        esac

        case "$3" in
        [0-1][0-9]) ;;
        2[0-3]) ;;
        *) return 1 ;;
        esac

        case "$4" in
        [0-5][0-9]) ;;
        *) return 1 ;;
        esac

        case "$5" in
        server) ;;
        exploitation) ;;
        *) return 1 ;;
        esac

        OLDIFS="$IFS"
        IFS="-"
               set -- $1 # $1=YYYY, $2=MM, $3=DD
        IFS="$OLDIFS"

        case "$1" in
        [2-9][0-9][0-9][0-9]) ;;
        *) return 1 ;;
        esac

        case "$2" in
        0[1-9]) ;;
        1[0-2]) ;;
        *) return 1 ;;
        esac

        case "$3" in
        0[1-9] | [1-2][0-9] | 3[0-1]) ;;
        *) return 1 ;;
        esac

        return 0
}
process() {
echo "$1 $2 $3 $4 $5 $6"
}

        if ! valid $1 $2 $3 $4 $5 $6 # Ignore invalid lines
        then
                echo "$1 $2 $3 $4 $5 $6 is invalid"
        else
        process $1 $2 $3 $4 $5 $6
fi

The bracketed expression consists of characters, emphasis on characters. [10] is not the number ten; it is the digit one followed by the digit zero. The range within the bracketed expression [9-10] does not mean nine to ten. It means nine to one along with an unrelated zero. The range [9-1], at best, will be empty and will match nothing. In that case, [9-10] is equivalent to [0]. At worst, [9-1] will yield an invalid range error message.

For all the details, consult your shell's manual page, specifically the section on pattern matching.

Regards,
Alister

Just to nit pick on alister's in depth comment, square brackets will always yield one single character only, either from the enumerated list of characters within, or from the (locale depending) char ranges within:

So [10] will match either 0 or 1 , nothing else.