I have the following little example with the regex /-+|(?<=: ?).*
. But this leads to an infinite loop in Node/Chrome and an "Invalig regex group"-error in Firefox.
When i change this to /-+|(?<=: ).*/gm
(Leaving out the ?-quantifier in the lookbehind) it runs but - of course - i don't get the lines which contain no value after the :
.
If i change the regex to /-+|(?<=:).*/gm
(leaving the space out of the lookbehind) i again run into an infinite loop/error.
Can anyone explain this behaviour to me and what regex i would have to use to also match the lines which end on a colon? I'd love to understand...
const text = `
-------------------------------------
Prop Name: 5048603
Prop2 Name:
Bla bla bla: asjhgg | a3857
Location: Something...
-------------------------------------
Prop Name: 5048603
Prop2 Name:
Bla bla bla: asjhgg | a3857
Location: Something...
-------------------------------------
`;
const pattern = /-+|(?<=: ?).*/gm;
let res;
while((res = pattern.exec(text)) !== null)
{
console.log(`"${res[0]}"`);
}
EDIT:
The expected output is:
"-------------------------------------"
"5048603"
""
"asjhgg | a3857"
"Something..."
"-------------------------------------"
"5048603"
""
"asjhgg | a3857"
"Something..."
"-------------------------------------"