well regarding the pattern, I don't really see why (?:\$)+ is at the end, it means 'at least one dollar sign after the ;' and maybe you need to make the '.' non-greedy by adding question marks: \$\(.*?\)\.test\(\d*\)\.(?:\r|\n|.)+?\);