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?

user5921
1#
user5921 Published in September 19, 2018, 4:02 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?

share|improve this question
  • 1
    Simply because you are matching [a-z] and digits are left out. Try with [a-z0-9] – Rahul Jan 12 at 17:51
  • Are you trying to match some specific devices or all? – Wiktor Stribi┼╝ew Jan 12 at 20:52

2 Answers 2

active oldest votes
up vote 2 down vote accepted
You need to login account before you can post.

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

© 2016 Powered by mzan.com design MATCHINFO