Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
XML parsing with regex
// regex_search example #include <iostream> #include <string> #include <regex> using namespace std; int main () { string s ("<?info?> <tag1 key1> <tag2 key2>contents2</tag2> <tag3> contents 3</tag3> <tag4 key contents/> </tag1>"); smatch m; regex e ("<(/*)(\\S+?)\\b(.*?)(/*)>"); // try to match <tag key> or <tag> or </tag> or <tag key/>, where // capture group 1: / - closing slash at the beginning of the short tag as in </tag> // capture group 2: tag - as in <tag key> // capture group 3: key - as in <tag key> // capture group 4: / - closing slash at the end of the of the long tag as in <tag key value/> while (regex_search (s,m,e, regex_constants::match_any)) // provide override default settings with POSIX, where extended mode (e.g. lazy quantifiers are not supported) { int i = 0; for (auto x:m) { if(i == 0) cout << "\nWhole match: "; else cout << "\nCapture group " << i << ": "; cout << x << " "; i++; } cout << "\n=================================\n"; s = m.suffix().str(); } return 0; }
run
|
edit
|
history
|
help
0
test
series kv type 1
C++ Solar eclipse program(Shoushi integrated) 1644 - 1785 from Ideone( Date: August 14, 2014 )
big boom!
hack qus
float
Dynamic Programming For Combinatorics - 1
Dec to Bin
Valuing Fixed Income Investments
BintTree vertical sum