replaced string.match with regexp.exec for simpler code.