Skip to content

Instantly share code, notes, and snippets.

@oakaigh
Last active January 27, 2019 15:54
Show Gist options
  • Save oakaigh/47e672d2e50c63d78e87f0089cf315bb to your computer and use it in GitHub Desktop.
Save oakaigh/47e672d2e50c63d78e87f0089cf315bb to your computer and use it in GitHub Desktop.
#include <algorithm>
#include <iostream>
#include <cctype>
#include <regex>
int main()
{
std::string str("server\t\n{ a = 5; b ={ a } c = what; } \nisthatthe{ case; }");
//str.erase(remove_if(str.begin(), str.end(), isspace), str.end());
std::regex expr("([^]+?)\\{([^]+?)\\}");
std::smatch matches;
for (std::sregex_iterator it(str.begin(), str.end(), expr), end_it; it != end_it; it++) {
std::cout << ">>>>>> START <<<<<<<" << std::endl;
std::cout << it->str() << std::endl;
std::cout << ">>>>>> END <<<<<<<" << std::endl;
}
/*if (std::regex_search(str, matches, expr)) {
for (size_t i = 1; i < matches.size(); i++) {
std::string match(matches[i].first, matches[i].second);
std::cout << "matches[" << i << "] = " << match << std::endl;
}
}*/
return 0;
}
@oakaigh
Copy link
Author

oakaigh commented Jan 27, 2019

std::string s = "text here++ text\n# text text\n# text\ntext text";
	std::regex r("#([^]+?)\\n");
	std::cout << std::regex_replace(s, r, "") << std::endl;
	return 0;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment