Regular Expression Parsing and evaluation in javascript