Text this: Formal specification and validation for pattern scanning