improved pattern matching by using regex replace to identify notelengths in advance