Refactor regex library