Regular expression error ?
-
I am trying to extract MAC address from text, and it is failing. Here is the debug print of the "inString" text to extract the MAC from :
"Inquiring ...\n\t98:D3:31:F8:39:33\tclock offset: 0x7c6b\tclass: 0x001f00\n"
Here is my temporary code with regular expression which must be in error, but I do not see it.
QRegularExpression re(" [^\x00-\x7F]+\\ *(?:[^\x00-\x7F]| )*");
QRegularExpressionMatch match = re.match(inString);if (match.hasMatch()) { text = " Has match "; QStringList result = match.capturedTexts(); text += result.at(0); // test show only first } else { text = " NO match found "; }
qDebug() << text;
Here is "run time error " , I am not sure why " invalid object" . Does it mean my regular expression is incorrect ?
QRegularExpressionPrivate::doMatch(): called on an invalid QRegularExpression object
" NO match found "If additional info would help, please ask. Help analyzing the expression would be also greatly appreciated. Thanks
-
I am trying to extract MAC address from text, and it is failing. Here is the debug print of the "inString" text to extract the MAC from :
"Inquiring ...\n\t98:D3:31:F8:39:33\tclock offset: 0x7c6b\tclass: 0x001f00\n"
Here is my temporary code with regular expression which must be in error, but I do not see it.
QRegularExpression re(" [^\x00-\x7F]+\\ *(?:[^\x00-\x7F]| )*");
QRegularExpressionMatch match = re.match(inString);if (match.hasMatch()) { text = " Has match "; QStringList result = match.capturedTexts(); text += result.at(0); // test show only first } else { text = " NO match found "; }
qDebug() << text;
Here is "run time error " , I am not sure why " invalid object" . Does it mean my regular expression is incorrect ?
QRegularExpressionPrivate::doMatch(): called on an invalid QRegularExpression object
" NO match found "If additional info would help, please ask. Help analyzing the expression would be also greatly appreciated. Thanks
You can validate your regex at any number of sites that do that sort of thing. That would help you determine if the problem is the regex itself, or the QRegularExpression object.
The difficult we do right away... ...the impossible takes slightly longer.
-
I am trying to extract MAC address from text, and it is failing. Here is the debug print of the "inString" text to extract the MAC from :
"Inquiring ...\n\t98:D3:31:F8:39:33\tclock offset: 0x7c6b\tclass: 0x001f00\n"
Here is my temporary code with regular expression which must be in error, but I do not see it.
QRegularExpression re(" [^\x00-\x7F]+\\ *(?:[^\x00-\x7F]| )*");
QRegularExpressionMatch match = re.match(inString);if (match.hasMatch()) { text = " Has match "; QStringList result = match.capturedTexts(); text += result.at(0); // test show only first } else { text = " NO match found "; }
qDebug() << text;
Here is "run time error " , I am not sure why " invalid object" . Does it mean my regular expression is incorrect ?
QRegularExpressionPrivate::doMatch(): called on an invalid QRegularExpression object
" NO match found "If additional info would help, please ask. Help analyzing the expression would be also greatly appreciated. Thanks
I can see one thing wrong with the expression right off the bat. You're trying to match hexadecimal characters from 00 to FF, but the range you specify is only 00 to 7F.
The difficult we do right away... ...the impossible takes slightly longer.
-
I can see one thing wrong with the expression right off the bat. You're trying to match hexadecimal characters from 00 to FF, but the range you specify is only 00 to 7F.
The difficult we do right away... ...the impossible takes slightly longer.
-
I am trying to extract MAC address from text, and it is failing. Here is the debug print of the "inString" text to extract the MAC from :
"Inquiring ...\n\t98:D3:31:F8:39:33\tclock offset: 0x7c6b\tclass: 0x001f00\n"
Here is my temporary code with regular expression which must be in error, but I do not see it.
QRegularExpression re(" [^\x00-\x7F]+\\ *(?:[^\x00-\x7F]| )*");
QRegularExpressionMatch match = re.match(inString);if (match.hasMatch()) { text = " Has match "; QStringList result = match.capturedTexts(); text += result.at(0); // test show only first } else { text = " NO match found "; }
qDebug() << text;
Here is "run time error " , I am not sure why " invalid object" . Does it mean my regular expression is incorrect ?
QRegularExpressionPrivate::doMatch(): called on an invalid QRegularExpression object
" NO match found "If additional info would help, please ask. Help analyzing the expression would be also greatly appreciated. Thanks
Mrs Google found this Regex.ai - Artificial Intelligence Regular Expression Generator[^] Now for questions : It is unclear how to select multiple entries from the text AKA highlight singe entry works , now to to select another part - dedicated by bold ? Bold text Devices:\n\thci0\t00:15:83:15:A2:CB\n For old fart the text is too small - is there a way to make it bigger or do I have to tell Ubuntu ?
-
I am trying to extract MAC address from text, and it is failing. Here is the debug print of the "inString" text to extract the MAC from :
"Inquiring ...\n\t98:D3:31:F8:39:33\tclock offset: 0x7c6b\tclass: 0x001f00\n"
Here is my temporary code with regular expression which must be in error, but I do not see it.
QRegularExpression re(" [^\x00-\x7F]+\\ *(?:[^\x00-\x7F]| )*");
QRegularExpressionMatch match = re.match(inString);if (match.hasMatch()) { text = " Has match "; QStringList result = match.capturedTexts(); text += result.at(0); // test show only first } else { text = " NO match found "; }
qDebug() << text;
Here is "run time error " , I am not sure why " invalid object" . Does it mean my regular expression is incorrect ?
QRegularExpressionPrivate::doMatch(): called on an invalid QRegularExpression object
" NO match found "If additional info would help, please ask. Help analyzing the expression would be also greatly appreciated. Thanks
Another option would be something like:
int pos1 = index of first \t in inString;
int pos2 = index of second \t in inString;
int length = pos2 - pos1;
string MAC = inString.substring(pos1, length);"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
-
Another option would be something like:
int pos1 = index of first \t in inString;
int pos2 = index of second \t in inString;
int length = pos2 - pos1;
string MAC = inString.substring(pos1, length);"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
Yes, this just proves there is more than one way to skin a cat... I did checked two AI regular expression generators and they came up with two solutions.. One pretty goofy. My current preference to match MAC address is : ([0-F]{2}[:]){5}[0-F]{2}) it "finds" the address, but also finds a single two character in it. The interesting part , the [0-F] apparently searches for characters between ASCII O and F - it does not search for digits. ( My opinion)
-
I am trying to extract MAC address from text, and it is failing. Here is the debug print of the "inString" text to extract the MAC from :
"Inquiring ...\n\t98:D3:31:F8:39:33\tclock offset: 0x7c6b\tclass: 0x001f00\n"
Here is my temporary code with regular expression which must be in error, but I do not see it.
QRegularExpression re(" [^\x00-\x7F]+\\ *(?:[^\x00-\x7F]| )*");
QRegularExpressionMatch match = re.match(inString);if (match.hasMatch()) { text = " Has match "; QStringList result = match.capturedTexts(); text += result.at(0); // test show only first } else { text = " NO match found "; }
qDebug() << text;
Here is "run time error " , I am not sure why " invalid object" . Does it mean my regular expression is incorrect ?
QRegularExpressionPrivate::doMatch(): called on an invalid QRegularExpression object
" NO match found "If additional info would help, please ask. Help analyzing the expression would be also greatly appreciated. Thanks
Google seems to return regular expressions to validate a mac address. Not to mention explaining forms that might be less than obvious.
mac address regular expression
Other than that the square brackets are used for character matching. Single character. Best I can tell you seem to be trying to match a sequence of characters (2 digit hex.)
-
Yes, this just proves there is more than one way to skin a cat... I did checked two AI regular expression generators and they came up with two solutions.. One pretty goofy. My current preference to match MAC address is : ([0-F]{2}[:]){5}[0-F]{2}) it "finds" the address, but also finds a single two character in it. The interesting part , the [0-F] apparently searches for characters between ASCII O and F - it does not search for digits. ( My opinion)
The range
[0-F]
includes the characters:;<=>@
, and does not include lowercase letetrs. You're better off either with[0-9a-fA-F]
. Alternatively, if your regex engine has character classes then you could use([[:xdigit:]]{2}[:]){5}[[:xdigit:]]{2}
I'm not sure you need to specify the colon as a match set, unless regex treats them as special characters.Keep Calm and Carry On
-
The range
[0-F]
includes the characters:;<=>@
, and does not include lowercase letetrs. You're better off either with[0-9a-fA-F]
. Alternatively, if your regex engine has character classes then you could use([[:xdigit:]]{2}[:]){5}[[:xdigit:]]{2}
I'm not sure you need to specify the colon as a match set, unless regex treats them as special characters.Keep Calm and Carry On
-
Thanks, as long as the entry is characters , not numbers, it makes sense. Since the MAC address "hex numbers" is capitals I do not need [a-f ]. You have a good point - I'll try to delete [:] - in theory it should work.
Salvatore Terress wrote:
Thanks, as long as the entry is characters , not numbers, it makes sense.
Why would they not be characters? You seem to be reading input from another command, so it should always be characters.
Salvatore Terress wrote:
Since the MAC address "hex numbers" is capitals I do not need [a-f ].
That depends. Can you guarantee that you'll always get upper case hex digits? Under linux, the arp commands uses lower case letters for the MAC address. Others might as well
Salvatore Terress wrote:
You have a good point - I'll try to delete [:] - in theory it should work.
It should. But as noted above, it would depend on where you're getting your input from. Under Windows, if you run
ipconfig /all
you get the Mac address separated by dashes e.g. "00-4B-35-30-35-34", so you may need to allow for that too.Keep Calm and Carry On
-
Yes, this just proves there is more than one way to skin a cat... I did checked two AI regular expression generators and they came up with two solutions.. One pretty goofy. My current preference to match MAC address is : ([0-F]{2}[:]){5}[0-F]{2}) it "finds" the address, but also finds a single two character in it. The interesting part , the [0-F] apparently searches for characters between ASCII O and F - it does not search for digits. ( My opinion)