Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <boost/xpressive/xpressive_static.hpp>
- using namespace boost::xpressive;
- int main()
- {
- std::string s = "3.89C";
- // re = ^([-+]?[0-9]+(\.[0-9]*)?)([CF])$
- sregex re = bos // ^
- >> (s1= // (
- !(set= '-', '+') // [-+]?
- >> +range('0', '9') // [0-9]+
- >> !(s2= '.' >> *range('0', '9')) // (\.[0-9]*)?
- ) // )
- >> (s3= (set= 'C', 'F')) // ([CF])
- >> eos; // $
- smatch what;
- if (regex_match(s, what, re)) {
- std::cout << what[0] << std::endl; // whole match
- std::cout << what[1] << std::endl; // first capture
- std::cout << what[2] << std::endl; // second capture
- std::cout << what[3] << std::endl; // third capture
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment