Hello All, I have recently been experimenting with Regular Expressions in C++ (Regex). Fortunately, I have worked with Regex before, but to my suprise, none of my expressions that I am familiar with as far as syntax work in C++. I am trying to isolate anything between two delimeters, but without the delimeters in the output. I need to loop through each result accordingly.
For example:
<Beginning>hi<End>
I want the code to return hi. I have tried the following code/Regular Expressions:
1 2 3 4 5 6 7 8
int main()
{
std::string str("This is just a simple sentence <Bank>hi<Bank> :start hi :end :start bob :end");
std::regex r(":start (.*?) :end"); // entire match will be 2 numbers
std::smatch m;
std::regex_search(str, m, r); //Searches str, places matches in m, and uses regex r.
for (auto v : m) std::cout << v << std::endl; //Loops through, displaying all tangable results.
}
This may be misleading, but I was simply testing by using :start and :end. If anyone can find a way to match the contents, but to remove the tags themselves, that would be great.
for the regular expressions themselves, I have looked all over the web for relevant answers with two delimiters, but all of them crash the program post compilation. Please help! Thanks, Drew.
Worth mentioning that your input statement looks like some markup language: If you allow arbitrary nesting of tags, then regular expressions won't be sufficient, even allowing for the fact that many real-life engines are substantially more powerful than the theoretical ones.