Efficient algorithms for pattern matching with general gaps, character classes, and transposition invariance