Originally from http://RegExpStudio.com. Minor patch to run under FPC (rather than Delphi on Windows).