Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
XML parsing with regex
Language:
Ada
Assembly
Bash
C#
C++ (gcc)
C++ (clang)
C++ (vc++)
C (gcc)
C (clang)
C (vc)
Client Side
Clojure
Common Lisp
D
Elixir
Erlang
F#
Fortran
Go
Haskell
Java
Javascript
Kotlin
Lua
MySql
Node.js
Ocaml
Octave
Objective-C
Oracle
Pascal
Perl
Php
PostgreSQL
Prolog
Python
Python 3
R
Rust
Ruby
Scala
Scheme
Sql Server
Swift
Tcl
Visual Basic
Layout:
Vertical
Horizontal
// 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; }
g++
Show compiler warnings
[
+
] Compiler args
[
+
]
Show input
edit mode
|
history
|
discussion