Вы можете использовать регулярные выражения, см. 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}`);
});
}
.
Мне нравится ответ Marc Garcia, потому что он показывает, как извлечь шаблонный параметр универсальным способом, но я полагаю, что его пример может быть более простым:
#include <type_traits>
#include <iostream>
template<int>
struct MyType {};
template<template <int> typename T, int N>
constexpr int extract(const T<N>&) { return N; }
int main() {
constexpr MyType<5> myObj;
std::cout << extract(myObj);
}