您可以使用正则表达式,请参见
https://regex101.com/
:
const regex = /accumulate.*price.*below/gm;
const str = `we could accumulate it at the price below 4000
we could do it at the price below 4000'`;
let m;
while ((m = regex.exec(str)) !== null) {
// This is necessary to avoid infinite loops with zero-width matches
if (m.index === regex.lastIndex) {
regex.lastIndex++;
}
// The result can be accessed through the `m`-variable.
m.forEach((match, groupIndex) => {
console.log(`Found match, group ${groupIndex}: ${match}`);
});
}