0
我试图让Qt使用QRegExp匹配MAC地址(1a:2b:3c:4d:5e:6f)。我似乎无法让它匹配 - 我做错了什么?Qt 4.8.4 MAC地址QRegExp
我迫使它试图匹配字符串:
"48:C1:AC:55:86:F3"
这里是我的尝试:
// Define a RegEx to match the 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 that the hexadecimal characters are upper case
hwAddress = hwAddress.toUpper();
qDebug() << "STRING TO MATCH: " << hwAddress << "MATCHED IT: " << regExMacAddress.indexIn(hwAddress) << " Exact Match: " << regExMacAddress.exactMatch(hwAddress);
// Check the mac address format
if (regExMacAddress.indexIn(hwAddress) == -1) {
你试过吗? http://stackoverflow.com/questions/4260467/what-is-a-regular-expression-for-a-mac-address – kenrogers 2013-05-08 13:50:48
是的 - 这些解决方案不适用于我的Qt。 – PhilBot 2013-05-08 14:04:37
你还没有显示你喂它的数据是什么样的。 – 2013-05-08 14:07:08