I have a bunch of strings and need to return substrings from them
The output should replace occurrences of
Test: intervening text - Exists
with
intervening text
I've tried:
const inputs = [
'Test: Text - N GTTTsds - Exists',
'Test: Text something here - Exists',
'Tictactoe foo baz - bar - Exists',
'Something still here',
'Joe Doe'
];
const output = [];
inputs.forEach(input => {
const resp = /(?:Test: )?(.+)(- Exists)?/.exec(input);
output.push(resp);
});
console.log(output);
but it doesn't produce the expected output of:
[
"Text - N GTTTsds",
"Text something here",
"Tictactoe foo baz - bar"
'Something still here',
'Joe Doe'
]
Exist(without thesat the end). Was that intentional?