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