Home Regex in C++ how to search for valid Linux Device Node?
Reply: 0

Regex in C++ how to search for valid Linux Device Node?

user518
1#
user518 Published in June 25, 2018, 7:51 am

Given a device node in Linux such as "/dev/sda1" or "/dev/sdb", I'd like to match all valid choices to know if I have a valid device node.

Here's what I have so far:

static bool isUSBNameValid(const std::string &node) {
    std::regex device("/dev/sd[a-z]*");

    if (std::regex_match(node, device)) {
            return true;
    }   

    return false;
}

This does not work. Why is this?

How to make this work with any valid Linux device node?

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.252529 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO