fork download
  1. #include <iostream>
  2. #include <regex>
  3. using namespace std;
  4.  
  5. int main() {
  6. // your code goes here
  7. std::string channel {"adapters/10:05:06:07:08:02/devices/30:00:00:00:00:04"};
  8. std::smatch base_match;
  9. const std::regex macPattern_d("adapters\\/(([A-Fa-f0-9]{2}[:]){5}([A-Fa-f0-9]{2}))\\/devices\\/(([A-Fa-f0-9]{2}[:]){5}([A-Fa-f0-9]{2}))");
  10. if(std::regex_match(channel, base_match, macPattern_d)) {
  11. // Extracted MAC address is valid
  12. for(auto& m : base_match)
  13. {
  14. std::cout << m << std::endl;
  15. }
  16. }
  17. else
  18. {
  19. const std::regex macPattern_a("adapters\\/(([A-Fa-f0-9]{2}[:]){5}([A-Fa-f0-9]{2}))");
  20. if(std::regex_match(channel, base_match, macPattern_a)) {
  21. // Extracted MAC address is valid
  22. for(auto& m : base_match)
  23. {
  24. std::cout << m << std::endl;
  25. }
  26. }
  27. }
  28. return 0;
  29. }
Success #stdin #stdout 0.01s 5308KB
stdin
Standard input is empty
stdout
adapters/10:05:06:07:08:02/devices/30:00:00:00:00:04
10:05:06:07:08:02
08:
02
30:00:00:00:00:04
00:
04