Monday, 13 March 2017

Regular expression for matching string from result (Javascript/Nodejs)

new to regex and nodejs. I have a program that calls a function then displays (result) in console such as below. How would a regular expression look like to match the "on":false string:

 {
   "state": {
   "on": false,
   "name": name,
   "date": date,
   "value": 254,
  },
 }

I currently have this but not really working for me. Does anyone have any idea what regular expression I would use to capture "ONLY" : "on":false, ?? Any help, suggestions greatly appreciated.

call.getStatus(22, function(err, result){
    if (err) throw err;
    displayStatus(result);
    var re = new RegExp("/^"on":false,$\");
    if (re.test(displayStatus)) {
        console.log("Valid");
    } else {
        console.log("Invalid");
    }   
});



via pyt

No comments:

Post a Comment