parse a mixed alphanumeric string from within a string

Hi,
I would like to be able to parse out a substring matching a basic pattern, which is a character followed by 3 or 4 digits (for example S1234 out of a larger string). The main string would just be a filename, like Thisis__the FileName_S1234_ToParse.txt. The filename isn't fixed, but the section of text I'd like(S1234) probably is. The numbers in S1234 aren't always the same (could be S4521 or S332 or any other 3 or 4 digit combination).
I've tried various combinations of tr, awk, grep, and sed, but haven't been able to find exactly the command to do it. I'm going through a lot of files and basically just need to identify each file by that S123 label. Anyone got a quick one or two liner that would do what I need?
-- The S123 can have 3 or 4 digits and the leading S can be upper or lowercase (yay for non-standardized filenames)
-- This is running on SunOs 5.8 (only have access to the tools that came with that version of Solaris)
-- I am trying to add this in to a csh script.

Any help would be greatly appreciated!

Thanks,

Keane

This is my initial thought (-r for GNU like seds, -E for BSD based seds), but I don't think it will fly on Solaris:

echo "Thisis__the FileName_S1234_ToParse.txt" |sed -E 's/(.*_)([sS][0-9]{3,4})(_.*)/\2/'

This might have an unseen flaw, but it works for the few cases I tried and I think it will work on Solaris too:

echo "Thisis__the FileName_S1234_ToParse.txt" |sed  's/.*__//; s/.*_S/S/; s/.*_s/s/; s/_.*//'

It allows the first set of double underbars to be followed by an s or S which is why the first substitute is there. It assumes that there are only the two other underbars in the name.

Hope it helps.

You could try nawk:

nawk 'match($0, "[Ss][0-9]{3,4}"){print substr($0,RSTART,RLENGTH) }'