Guest User

Untitled

a guest
Nov 15th, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. #include <iostream>
  2. #include <boost/xpressive/xpressive_static.hpp>
  3. using namespace boost::xpressive;
  4.  
  5. int main()
  6. {
  7. std::string s = "3.89C";
  8.  
  9. // re = ^([-+]?[0-9]+(\.[0-9]*)?)([CF])$
  10. sregex re = bos // ^
  11. >> (s1= // (
  12. !(set= '-', '+') // [-+]?
  13. >> +range('0', '9') // [0-9]+
  14. >> !(s2= '.' >> *range('0', '9')) // (\.[0-9]*)?
  15. ) // )
  16. >> (s3= (set= 'C', 'F')) // ([CF])
  17. >> eos; // $
  18.  
  19. smatch what;
  20. if (regex_match(s, what, re)) {
  21. std::cout << what[0] << std::endl; // whole match
  22. std::cout << what[1] << std::endl; // first capture
  23. std::cout << what[2] << std::endl; // second capture
  24. std::cout << what[3] << std::endl; // third capture
  25. }
  26.  
  27. return 0;
  28. }
Add Comment
Please, Sign In to add comment