Avoid TypeError when accessing matches

Accessing length on matches may cause a TypeError if matches isn't an array.