moved regex at top of the script and fixed bug with documents starting with colon