I'm not sure if that's what the code already does, but would it make sense to split the field of letters into a set of strings line-by-line for each direction and then grep that list?
E.g. if we have a letter block like this:
BWSK
ASDW
LDKS
SDAD
we would generate the following set of strings:
'BWSK', 'ASDW', ..., 'BALS', 'WSDD', 'SDKA', etc (include the diagonal ones as well if necessary). Then we can search through that.