Merging and splitting chunks with regular expressions