I am trying to get lines from a string parameter and copy them in a new string variable. This logic will execute as long as the new line doesn't match a particular regex expression.
From some reason (unknown to me) the output it's what I've expected....
This is the code:
matchRegexExp(log: string) {
let regexString = /(?:\d{4}-\d{2}-\d{2}\s+\d{2}:\d{2}:\d{2})[\s\S]+?((?=\d{4}-\d{2}-\d{2}\s+\d{2}:\d{2}:\d{2})|$)/g;
return log.match(regexString);
}
}
private createString(string1: string) {
let i: number = 0;
let readLine: string[] = string1.split('\n');
let x: string ='';
while (this.matchRegexExp(readLine[i]) == null) {
console.log('regex expression returns... ' + this.matchRegexExp(readLine[i]));
console.log('current line content is... ', readLine[i]);
console.log('x is = ', x);
x = x + readLine[i];
console.log('new x is ',x , '\n');
i++;
}
console.log('final x is = ', x, '\n');
return x;
}
This is the data from string1:
ana
has
apples
and
oranges
2019-01-01 11:11:11 INFO ThisApp - Started App
The lines that do not match my regex expression and that have to be copied in the string are:
ana
has
apples
and
oranges
But when I run the code... I get this 'weird' output:
regex expression returns... null
current line content is... ana
x is =
ew x is ana
regex expression returns... null
current line content is... has
x is = ana
as x is ana
regex expression returns... null
current line content is... apples
hass = ana
pplesis ana
regex expression returns... null
current line content is... and
apples ana
nd esis ana
regex expression returns... null
current line content is... oranges
and es ana
oranges ana
orangess = ana
this.matchRegexExp?let regexString = *some regex expression*;isn't valid js and the braces don't actually match