Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Regular expression error ?

Regular expression error ?

Scheduled Pinned Locked Moved C / C++ / MFC
regexhelpdebuggingquestion
12 Posts 6 Posters 33 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    Lost User
    wrote on last edited by
    #1

    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

    Richard Andrew x64R L D J 5 Replies Last reply
    0
    • L Lost User

      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

      Richard Andrew x64R Offline
      Richard Andrew x64R Offline
      Richard Andrew x64
      wrote on last edited by
      #2

      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.

      1 Reply Last reply
      0
      • L Lost User

        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

        Richard Andrew x64R Offline
        Richard Andrew x64R Offline
        Richard Andrew x64
        wrote on last edited by
        #3

        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.

        L 1 Reply Last reply
        0
        • Richard Andrew x64R Richard Andrew x64

          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.

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          Yes, I found that error too. It still fails. I am going t0 verify the expression using on one of the test sites...

          1 Reply Last reply
          0
          • L Lost User

            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

            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #5

            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 ?

            1 Reply Last reply
            0
            • L Lost User

              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

              D Offline
              D Offline
              David Crow
              wrote on last edited by
              #6

              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

              L 1 Reply Last reply
              0
              • D David Crow

                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

                L Offline
                L Offline
                Lost User
                wrote on last edited by
                #7

                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)

                K R 2 Replies Last reply
                0
                • L Lost User

                  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

                  J Offline
                  J Offline
                  jschell
                  wrote on last edited by
                  #8

                  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.)

                  1 Reply Last reply
                  0
                  • L Lost User

                    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)

                    K Offline
                    K Offline
                    k5054
                    wrote on last edited by
                    #9

                    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

                    L 1 Reply Last reply
                    0
                    • K k5054

                      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

                      L Offline
                      L Offline
                      Lost User
                      wrote on last edited by
                      #10

                      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.

                      K 1 Reply Last reply
                      0
                      • L Lost User

                        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.

                        K Offline
                        K Offline
                        k5054
                        wrote on last edited by
                        #11

                        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

                        1 Reply Last reply
                        0
                        • L Lost User

                          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)

                          R Offline
                          R Offline
                          RedDk
                          wrote on last edited by
                          #12

                          Salvatore Terress wrote:

                          ([0-F]{2}[:]){5}[0-F]{2})

                          Should be: ([0-F]{2}[:]){5}[0-F]{2}

                          1 Reply Last reply
                          0
                          Reply
                          • Reply as topic
                          Log in to reply
                          • Oldest to Newest
                          • Newest to Oldest
                          • Most Votes


                          • Login

                          • Don't have an account? Register

                          • Login or register to search.
                          • First post
                            Last post
                          0
                          • Categories
                          • Recent
                          • Tags
                          • Popular
                          • World
                          • Users
                          • Groups