Perl!
#!/usr/bin/perl
use strict;
use warnings;
my $ex1 = '#S(5,Hello)';
$ex1 =~ /\#S\((\d+),(\w*)\)/;
if ($1 == length($2)) {
print "match\n";
} else {
print "does not match\n";
}
Essentially just extract the number and the text in subpatterns, then compare them.