Take regexp out of loop