Use imperative style and standard JS regex

Based on pull request feedback