fix more bugs with indexes by splitting ' and - from the ends of words; and fix invalid-chars regex