How to fetch text between 2 texts or end of text with regex ?

How to fetch text between 2 texts
or end of text with std::regex ?

1
2
3
4
5
6
7
8
9
10
11
12
#include <regex>
#include <iostream>

int main()
{
    const std::string s = "Ipsum liripsum limsum sapsum nit";
    std::regex rgx("liripsum (\\w+) sapsum");
    std::smatch match;

    if (std::regex_search(s.begin(), s.end(), match, rgx))
        std::cout << "match: " << match[1] << '\n';
}
Last edited on
Something like:

 
    std::regex rgx("liripsum +(\\w+)(?: +sapsum|$)");

Last edited on
Topic archived. No new replies allowed.