Fixed local formatting tokens detection

According to the docs:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/test
issuing regex.test on the same regex that is also g (global), would cause it to
remember the last match position and continue from there. Set lastIndex to
0 before every test to make sure this won't happen.
Merge pull request #971 from ichernev/bugfix/global-regexp-test

Fixed local formatting tokens detection

Apparently global regexes remember the last matched position after `test`. Reset that that before each test.