Skip to content

Instantly share code, notes, and snippets.

@martin-ueding
Last active August 29, 2015 14:01
Show Gist options
  • Save martin-ueding/faaeba78413db8fe67d0 to your computer and use it in GitHub Desktop.
Save martin-ueding/faaeba78413db8fe67d0 to your computer and use it in GitHub Desktop.
// Copyright © 2014 Martin Ueding <dev@martin-ueding.de>
#include <iostream>
#include <regex>
int main() {
std::string haystack {"This\nhas\nnewlines."};
std::regex regex {"\n"};
std::string replacement {"\n# "};
std::string result {std::regex_replace(haystack, regex, replacement)};
std::cout << "-->" << result << "<--" << std::endl;
return 0;
}
// $ clang++ -std=c++11 -Wall regex.cpp; and ./a.out
// --><--
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment