fork download
  1. #include<regex>
  2. #include <iostream>
  3. using namespace std;
  4.  
  5. bool isUSBNameValid(const std::string &node, std::regex device) {
  6. if (std::regex_match(node, device)) {
  7. return true;
  8. }
  9. return false;
  10. }
  11. int main() {
  12. std::regex device_sata("/dev/sd[a-z][0-9]*");
  13. std::regex device_any("/dev/[[:alnum:]]+");
  14. cout<< ( isUSBNameValid("/dev/sda1", device_sata) ? "Found" : "Not found")<<endl;
  15. cout<< ( isUSBNameValid("/dev/sdb", device_sata) ? "Found" : "Not found")<<endl;
  16. cout<< ( isUSBNameValid("/dev/ttyS0", device_any) ? "Found" : "Not found")<<endl;
  17. return 0;
  18. }
Success #stdin #stdout 0s 4332KB
stdin
Standard input is empty
stdout
Found
Found
Found