Tim Stone's fix for patterns ending with underscore, http://meta.mathematica.stackexchange.com/a/392
some minor readability, size, and regex optimization
update user script to match