pattern match in Javascript