Sed extract substring on (OS X)

On OS 10.4.11

I have filenames like:

670711 SA T2 v1-1_DS_EF.doc
CT_670520 AM T1 v1-2_DS_EF.doc
CT_670716 - 2 SA T4 v1-2_DS_EF.doc
CT_670713 SA T3 v1-1_DS_EF.doc
670421 PA DYP1 v1-1_DS_EF.doc
CT_670425 PA DYP2 v1-1_DS_EF.doc
CT_670107 RA T3 v1-2_DS_EF.doc
CT_670521 AM T2 v1-2_DS_EF.doc
CT_670718-1 SA T5 v1-2_DS_EF.doc

I want extract the substrings in bold and assign to a variable.

I'm trying this:

datedid=`echo $tname | sed 's/\([[:digit:]]\{6\}[-]?[[:digit:]]?\)/\1/'`

But this simply returns $tname unaffected.

I have also tried:

datedid=`echo $tname | sed -E 's/\([[:digit:]]\{6\}[-]?[[:digit:]]?\)/\1/'`

But gives and error that "\1 not defined in the RE".

Have spent the morning googling and reading, but missing something here...Any sed gurus out there?

datedid=$(echo $tname | sed 's/^\([A-Z_]*[0-9][0-9]*[- 0-9]*\).*/\1/')

If you have Perl available, you can try this:

echo $tname | perl -pe 's/.*(\d\d\d\d\d\d\s?-?\s?\d?).*/$1/'

Hope this helps.

First time I've used Perl; I like the syntax and didn't realize you could embed it that simply. Worked a charm.

Thanks shamrock also for the sed help; I've seen the use of double brackets like that: [0-9][0-9] but still not sure why that works? Seems like from other examples of sed, extended regular expressions should be available...?

Cheers all.