fix greedy regexps, case-sensitive close regexp, add tests