use while loop to simplify regular expression. possible fix for #55