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!!!

Regular expression!!!

Scheduled Pinned Locked Moved C / C++ / MFC
helpregextutorial
12 Posts 5 Posters 0 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.
  • _ Offline
    _ Offline
    _AnsHUMAN_
    wrote on last edited by
    #1

    HI All, I have a string. In this string I want to validate that if and only if the previous character is something then the next character should also follow a definite pattern. For ex: A_____B______C_____D_____E 3_____1______2_____0_____3 _____________4_____0_____1 ___________________1_____2 ______2______1_____1_____0 ______4______2_____3_____2 so as explained in the table above the valid entries should be 31203,31412,32110,34232. I have tried solving the issue with a lots of if's, else if's etc. but I somewhere feel that this may not be the right way to validate the input. Can somebody put some light on this issue or point me to some article link that may help me to the resolution of the problem..... Thanks in advance

    Somethings seem HARD to do, until we know how to do them. ;-)_AnShUmAn_

    T D K 3 Replies Last reply
    0
    • _ _AnsHUMAN_

      HI All, I have a string. In this string I want to validate that if and only if the previous character is something then the next character should also follow a definite pattern. For ex: A_____B______C_____D_____E 3_____1______2_____0_____3 _____________4_____0_____1 ___________________1_____2 ______2______1_____1_____0 ______4______2_____3_____2 so as explained in the table above the valid entries should be 31203,31412,32110,34232. I have tried solving the issue with a lots of if's, else if's etc. but I somewhere feel that this may not be the right way to validate the input. Can somebody put some light on this issue or point me to some article link that may help me to the resolution of the problem..... Thanks in advance

      Somethings seem HARD to do, until we know how to do them. ;-)_AnShUmAn_

      T Offline
      T Offline
      toxcct
      wrote on last edited by
      #2

      something like this ?? :rolleyes:

      (3 [1 [(2 0 3) | (4 [(0 1) | (1 2)])] | (2 1 1 0) | (4 2 3 2)])


      You don't know where to start ? ask a good friend

      [VisualCalc 3.0][Flags Beginner's Guide]

      1 Reply Last reply
      0
      • _ _AnsHUMAN_

        HI All, I have a string. In this string I want to validate that if and only if the previous character is something then the next character should also follow a definite pattern. For ex: A_____B______C_____D_____E 3_____1______2_____0_____3 _____________4_____0_____1 ___________________1_____2 ______2______1_____1_____0 ______4______2_____3_____2 so as explained in the table above the valid entries should be 31203,31412,32110,34232. I have tried solving the issue with a lots of if's, else if's etc. but I somewhere feel that this may not be the right way to validate the input. Can somebody put some light on this issue or point me to some article link that may help me to the resolution of the problem..... Thanks in advance

        Somethings seem HARD to do, until we know how to do them. ;-)_AnShUmAn_

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

        Could you possibly employ the use of a FSM?


        "Approved Workmen Are Not Ashamed" - 2 Timothy 2:15

        "Judge not by the eye but by the heart." - Native American Proverb

        C 1 Reply Last reply
        0
        • D David Crow

          Could you possibly employ the use of a FSM?


          "Approved Workmen Are Not Ashamed" - 2 Timothy 2:15

          "Judge not by the eye but by the heart." - Native American Proverb

          C Offline
          C Offline
          Chris Losinger
          wrote on last edited by
          #4

          DavidCrow wrote:

          Could you possibly employ the use of a FSM

          there is only one FSM. and he works for nobody.

          image processing | blogging

          1 Reply Last reply
          0
          • _ _AnsHUMAN_

            HI All, I have a string. In this string I want to validate that if and only if the previous character is something then the next character should also follow a definite pattern. For ex: A_____B______C_____D_____E 3_____1______2_____0_____3 _____________4_____0_____1 ___________________1_____2 ______2______1_____1_____0 ______4______2_____3_____2 so as explained in the table above the valid entries should be 31203,31412,32110,34232. I have tried solving the issue with a lots of if's, else if's etc. but I somewhere feel that this may not be the right way to validate the input. Can somebody put some light on this issue or point me to some article link that may help me to the resolution of the problem..... Thanks in advance

            Somethings seem HARD to do, until we know how to do them. ;-)_AnShUmAn_

            K Offline
            K Offline
            kakan
            wrote on last edited by
            #5

            _AnShUmAn_ wrote:

            A_____B______C_____D_____E 3_____1______2_____0_____3 _____________4_____0_____1 ___________________1_____2 ______2______1_____1_____0 ______4______2_____3_____2 so as explained in the table above the valid entries should be 31203,31412,32110,34232.

            I'm missing one value. I guess the correct entries should be 31203,31401,31412,32110,34232. Am I right? Further: 1. The underscore characters, are they present in the string? 2.

            _AnShUmAn_ wrote:

            A_____B______C_____D_____E

            Does this line have any significance, or did you just put it there for clarification?

            Alcohol. The cause of, and the solution to, all of life's problems - Homer Simpson

            _ 1 Reply Last reply
            0
            • K kakan

              _AnShUmAn_ wrote:

              A_____B______C_____D_____E 3_____1______2_____0_____3 _____________4_____0_____1 ___________________1_____2 ______2______1_____1_____0 ______4______2_____3_____2 so as explained in the table above the valid entries should be 31203,31412,32110,34232.

              I'm missing one value. I guess the correct entries should be 31203,31401,31412,32110,34232. Am I right? Further: 1. The underscore characters, are they present in the string? 2.

              _AnShUmAn_ wrote:

              A_____B______C_____D_____E

              Does this line have any significance, or did you just put it there for clarification?

              Alcohol. The cause of, and the solution to, all of life's problems - Homer Simpson

              _ Offline
              _ Offline
              _AnsHUMAN_
              wrote on last edited by
              #6

              kakan wrote:

              I'm missing one value

              I just gave a few examples about how the values could be entered by the user. Yes what you is correct.

              kakan wrote:

              The underscore characters, are they present in the string?

              NO the underscore signs are not present in the string. I just entered them to show the alignment to the codeproject member's.

              kakan wrote:

              A_____B______C_____D_____E

              I just put this line for clarification.

              Somethings seem HARD to do, until we know how to do them. ;-)_AnShUmAn_

              K 2 Replies Last reply
              0
              • _ _AnsHUMAN_

                kakan wrote:

                I'm missing one value

                I just gave a few examples about how the values could be entered by the user. Yes what you is correct.

                kakan wrote:

                The underscore characters, are they present in the string?

                NO the underscore signs are not present in the string. I just entered them to show the alignment to the codeproject member's.

                kakan wrote:

                A_____B______C_____D_____E

                I just put this line for clarification.

                Somethings seem HARD to do, until we know how to do them. ;-)_AnShUmAn_

                K Offline
                K Offline
                kakan
                wrote on last edited by
                #7

                OK, one more question: The "shorter" lines, are they left justified, or are they padded with blanks? Like this (padded with blanks): "31203" " 401" " 12" " 2110" " 4232" Or like this (left justified): "31203" "401" "12" "2110" "4232" I'm working on a solution. -- modified at 1:43 Tuesday 7th November, 2006 -- modified at 1:44 Tuesday 7th November, 2006 Alcohol. The cause of, and the solution to, all of life's problems - Homer Simpson

                1 Reply Last reply
                0
                • _ _AnsHUMAN_

                  kakan wrote:

                  I'm missing one value

                  I just gave a few examples about how the values could be entered by the user. Yes what you is correct.

                  kakan wrote:

                  The underscore characters, are they present in the string?

                  NO the underscore signs are not present in the string. I just entered them to show the alignment to the codeproject member's.

                  kakan wrote:

                  A_____B______C_____D_____E

                  I just put this line for clarification.

                  Somethings seem HARD to do, until we know how to do them. ;-)_AnShUmAn_

                  K Offline
                  K Offline
                  kakan
                  wrote on last edited by
                  #8

                  Hello again. I didn't receive an answer to my last question, but I made a solution that covers both cases. You will have to adjust the code for Unicode if you want it. And possibly adjust the code to ATL/STL if you want it. Here goes: The func: void get(CString csIn, CString &csOut) { static CString csLast = ""; int lastLen = csLast.GetLength(); // Ignore and remove leading blanks in csIn. while(csIn.GetAt(0) == ' ') csIn.Delete(0); int inLen = csIn.GetLength(); if(inLen >= lastLen) { // New, bigger value, save it. csLast = csIn; lastLen = csLast.GetLength(); } int copyChars = lastLen - inLen; if(copyChars > 0) { csOut = csLast.Left(copyChars); } else csOut = ""; csOut += csIn; csLast = csOut; // Save the last value for next time. } The main: CString csRet; get("31203", csRet); // csRet becomes "31203" get(" 401", csRet); // csRet becomes "31401" get(" 12", csRet); // csRet becomes "31412" get(" 2110", csRet); // csRet becomes "32110" get(" 4232", csRet); // csRet becomes "34232" Alcohol. The cause of, and the solution to, all of life's problems - Homer Simpson

                  _ D 2 Replies Last reply
                  0
                  • K kakan

                    Hello again. I didn't receive an answer to my last question, but I made a solution that covers both cases. You will have to adjust the code for Unicode if you want it. And possibly adjust the code to ATL/STL if you want it. Here goes: The func: void get(CString csIn, CString &csOut) { static CString csLast = ""; int lastLen = csLast.GetLength(); // Ignore and remove leading blanks in csIn. while(csIn.GetAt(0) == ' ') csIn.Delete(0); int inLen = csIn.GetLength(); if(inLen >= lastLen) { // New, bigger value, save it. csLast = csIn; lastLen = csLast.GetLength(); } int copyChars = lastLen - inLen; if(copyChars > 0) { csOut = csLast.Left(copyChars); } else csOut = ""; csOut += csIn; csLast = csOut; // Save the last value for next time. } The main: CString csRet; get("31203", csRet); // csRet becomes "31203" get(" 401", csRet); // csRet becomes "31401" get(" 12", csRet); // csRet becomes "31412" get(" 2110", csRet); // csRet becomes "32110" get(" 4232", csRet); // csRet becomes "34232" Alcohol. The cause of, and the solution to, all of life's problems - Homer Simpson

                    _ Offline
                    _ Offline
                    _AnsHUMAN_
                    wrote on last edited by
                    #9

                    Thanks for your time and effort both in helping me to find out the solution. I will give it a try and let you know if there is still some problem that needs to be dealt with. Thanks once again.

                    Somethings seem HARD to do, until we know how to do them. ;-)_AnShUmAn_

                    K 1 Reply Last reply
                    0
                    • _ _AnsHUMAN_

                      Thanks for your time and effort both in helping me to find out the solution. I will give it a try and let you know if there is still some problem that needs to be dealt with. Thanks once again.

                      Somethings seem HARD to do, until we know how to do them. ;-)_AnShUmAn_

                      K Offline
                      K Offline
                      kakan
                      wrote on last edited by
                      #10

                      Your'e welcome, I'm glad if I can be of assistance to you. And I can't resist a challenge... Probably, there are things that must be fixed, this is a quick hack. But I think the main idea works. Good luck. Kakan

                      Alcohol. The cause of, and the solution to, all of life's problems - Homer Simpson

                      1 Reply Last reply
                      0
                      • K kakan

                        Hello again. I didn't receive an answer to my last question, but I made a solution that covers both cases. You will have to adjust the code for Unicode if you want it. And possibly adjust the code to ATL/STL if you want it. Here goes: The func: void get(CString csIn, CString &csOut) { static CString csLast = ""; int lastLen = csLast.GetLength(); // Ignore and remove leading blanks in csIn. while(csIn.GetAt(0) == ' ') csIn.Delete(0); int inLen = csIn.GetLength(); if(inLen >= lastLen) { // New, bigger value, save it. csLast = csIn; lastLen = csLast.GetLength(); } int copyChars = lastLen - inLen; if(copyChars > 0) { csOut = csLast.Left(copyChars); } else csOut = ""; csOut += csIn; csLast = csOut; // Save the last value for next time. } The main: CString csRet; get("31203", csRet); // csRet becomes "31203" get(" 401", csRet); // csRet becomes "31401" get(" 12", csRet); // csRet becomes "31412" get(" 2110", csRet); // csRet becomes "32110" get(" 4232", csRet); // csRet becomes "34232" Alcohol. The cause of, and the solution to, all of life's problems - Homer Simpson

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

                        kakan wrote:

                        // Ignore and remove leading blanks in csIn. while(csIn.GetAt(0) == ' ') csIn.Delete(0);

                        What's wrong with CString::TrimLeft()?


                        "Approved Workmen Are Not Ashamed" - 2 Timothy 2:15

                        "Judge not by the eye but by the heart." - Native American Proverb

                        K 1 Reply Last reply
                        0
                        • D David Crow

                          kakan wrote:

                          // Ignore and remove leading blanks in csIn. while(csIn.GetAt(0) == ' ') csIn.Delete(0);

                          What's wrong with CString::TrimLeft()?


                          "Approved Workmen Are Not Ashamed" - 2 Timothy 2:15

                          "Judge not by the eye but by the heart." - Native American Proverb

                          K Offline
                          K Offline
                          kakan
                          wrote on last edited by
                          #12

                          There is nothing wrong with TrimLeft (i hope). I agree, it's a better choice. But I didn't have the time to tidy up the code. I'm at work, and wanted to help out...

                          Alcohol. The cause of, and the solution to, all of life's problems - Homer Simpson

                          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