-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathregex.cpp
27 lines (23 loc) · 836 Bytes
/
regex.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include <iostream>
#include <string>
#include <regex>
//http://www.cplusplus.com/reference/regex/regex_match/
//http://www.cplusplus.com/reference/regex/regex_replace/
int main(){
std::string mystr = "hello, good bye and hello";
std::regex pattern("(hello)(.*)");
if(std::regex_match(mystr, pattern)){
std::cout << mystr << " matches the pattern" << std::endl;
}
mystr = "<DIV>This is the first line <![CDATA[<div>]]></DIV>";
std::cout << "before: " << mystr << std::endl;
pattern = std::regex("<!\\[CDATA\\[.*?\\]\\]>");
mystr = regex_replace(mystr, pattern, "c");
std::cout << "after: " << mystr << std::endl;
return 0;
}
/*
hello, good bye and hello matches the pattern
before: <DIV>This is the first line <![CDATA[<div>]]></DIV>
after: <DIV>This is the first line c</DIV>
*/