Move regexp searching from DB to script