regex - Qt 4.8.4 MAC Address QRegExp -
i'm trying qt match mac address ( 1a:2b:3c:4d:5e:6f ) using qregexp. can't seem match - doing wrong?
i forcing try , match string:
"48:c1:ac:55:86:f3"
here attempts:
// define regex match mac address //qregexp regexmacaddress("[0-9a-f]{1,2}[\.:-]){5}([0-9a-f]{1,2}"); //qregexp regexmacaddress("[0-9a-f]{0,2}:[0-9a-f]{0,2}:[0-9a-f]{0,2}:[0-9a-f]{0,2}:[0-9a-f]{0,2}:[0-9a-f]{0,2}"); //regexmacaddress.setpatternsyntax(qregexp::regexp); // ensure hexadecimal characters upper case hwaddress = hwaddress.toupper(); qdebug() << "string match: " << hwaddress << "matched it: " << regexmacaddress.indexin(hwaddress) << " exact match: " << regexmacaddress.exactmatch(hwaddress); // check mac address format if ( regexmacaddress.indexin(hwaddress) == -1 ) {
in first example opening bracket missing , \.
incorrect (read help explanations), in both a-f
matches nothing, due 'a' > 'f'
.
the correct answer can find in comment of kenrogers
, i'll duplicate you:
([0-9a-f]{2}[:-]){5}([0-9a-f]{2})
if want match .
should use:
([0-9a-f]{2}[:-\\.]){5}([0-9a-f]{2})
if want match lower case characters, should use:
([0-9a-fa-f]{2}[:-\\.]){5}([0-9a-fa-f]{2})
Comments
Post a Comment