Add duplicate function

Replace regular expressions with smartmatches