Regex Pattern Structure Javascript Foreach Loop