i am trying to do this:
render(argv,function() {
var fileHandle = argv.output + '/docu.html';
var regex_ca_id = new RegExp('[A-Za-z1-9]{16}#[A-Za-z1-9]{5}',"g");
var rd = readline.createInterface({
input: fs.createReadStream(fileHandle),
output: process.stdout,
terminal: false
});
rd.on('line', function(line) {
if(regex_ca_id.test(line)) {
console.log('Debug: '+regex_ca_id.test(line)+
' '+regex_ca_id.exec(line)+' '+line);
}
rd.close();
process.stdin.destroy();
});
on a html file ("fileHandle" see above) which contains lines like:
<p class="img-container"><img src="UU4GBVJyst5kqS8O#732F4-50" alt="I am a picture" title="An Image"></p>
<p>Dies ist <a href="UU4GBVJyst5kqS8O#732F4-50" title="An Image">ein Beispiel</a> für einen Referenz-Link.</p>
which produces this output which is emitted by the console.log() lines:
Debug: false UU47GZJyst5kqS8O#732F4 <p class="img-container"><img src="UU4GBVJyst5kqS8O#732F4-50" alt="I am a picture" title="An Image"></p>
Debug: false UU47GZJyst5kqS8O#732F4 <p>Dies ist <a href="UU4GBVJyst5kqS8O#732F4-50" title="An Image">ein Beispiel</a> für einen Referenz-Link.</p>
The output is something i didn´t expect. regex_ca_id.test(line) evaluates to true, so the the body of the if construct starts. Now the same statement inside console.log evaluates to false, after this an exec() on the previous used RegExp object returns the successful matched string.
Additional usage of:
var result = regex_ca_id.exec(line);
inside the rd.on block will get assigned to null.
This looks inconsistent to me, thank you for helping me out to understand this behaviour.
Stephen