New regular expression code. Fixes #27