I have a specific text format that goes like this:
test/something
The test/
part always remains the same, but the word following it varies. I am trying to extract the word after test/
, which is essentially what I need. Sometimes, this pattern appears within a sentence, such as:
Please grab the word after test/something thank you
.
In this scenario, I only want to capture something
, not the additional words like thank you
.
I came up with this code:
const start = text.indexOf('test/');
const end = text.substring(start).indexOf(' ') + start;
const result = text.substring(start, end).replace('test/', '');
This solution works when the pattern is surrounded by spaces in a sentence. How can I modify it to handle all cases, even if the input string consists solely of test/something
without any other characters before or after it?