Someone know how to I can do? I need to find the following words to a word until the end point.
Text example:
Product: My wonderful product.
I need: My wonderful product
I have managed to find the next word but not the others until the final point with this code:
const product= 'PRODUCT:';
let result = text.match(new RegExp(product+ '\\s(\\w+)', 'i'));
if (result != null) {
result = result[1];
}
Thanks.
// Input = Product: My wonderful product.
// Output = My wonderful product
const text = 'Product: My wonderful product.';
const product = 'PRODUCT: ';
const matches = text.match(new RegExp(`(?:${product})(.*)`, 'i'));
let result;
if (matches && matches.length === 2) {
result = matches[1];
} else {
result = '';
}
console.log(result)
See https://regex101.com/r/ZA4qHz/1/ to debug.
Relevant docs: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With