Add error checking and more precise regexp