Sunday, 12 March 2017

regex with named capture fails in XRegExp but works fine on regex101.com [duplicate]

This question already has an answer here:

I apologize in advance if this is due to some newbie mistake, but I cannot seem to get this regex to work with XRegExp, while it works fine on regex101:

https://regex101.com/r/8j0Ml5/1

I have setup a fiddle that fails these tests:

https://jsfiddle.net/he2dk8kc/

Here is the original code I am using in node:

const XRegExp = require('xregexp');
let testStr = '12:27:57 up 25 min,  load average: 0.33, 0.33, 0.28';
var uptimeRegex = XRegExp('(?<timeHour>\d{1,2}):(?<timeMinute>\d{2})(?:\:(?<timeSecond>\d{2}))?\s+up\s+(?:(?<upDays>\d+)\s+days?,\s+)?\b(?:(?<upHours>\d+):)?(?<upMinutes>\d+)(?:\s+min?)?,\s+.+?(?<load1>\d+\.\d+),?\s+(?<load2>\d+\.\d+),?\s+(?<load3>\d+\.\d+)', 'ni');
let test = uptimeRegex.test(testStr);
=> false

Any advice would be appreciated, as I am not sure why this is failing.

Thank you



via OIST AV

No comments:

Post a Comment