String matching with patterns