2 Replies Latest reply on Feb 3, 2021 2:29 AM by SP K

    extract no form string

    SP K Seasoned Veteran

      Hi Team,

       

      My file name will be " Test_file_formate-02182011-Type-23.txt " and i need to capture 02182011

      i tried using REG_EXTRACT(File_Name,'(\d+)([A-Z]+)',1) but it was returing returning null value

       

      my date portion can be MMDDYYYY (or) MDDYYYY so i am not able to use Substring to extract based on file length.

       

      Please sugest.

       

      Thanks
      Nag

        • 1. Re: extract no form string
          Nico Heinze Guru

          Regarding the REG_EXTRACT() call: the format is "wrong" insofar that the format string must contain all the "superfluous" characters as well, meaning you would need something like this (assuming that the part before the date will always be "some text" plus a minus sign):

              Reg_Extract( File_Name, '[^-]*-(\d+)-.*.txt', 1)

          What does that mean?

          First there's some "noise" up to the first minus character (this "noise" never contains a minus character itself).

          Then there are some digits which we want to extract (hence the parentheses "(...)" around the \d+).

          Finally there's one more minus sign followed by some arbitrary characters followed by ".txt".

           

          BTW assuming that the two minus signs always enclose the date, you can use SUBSTR() to get the date. Do it this way:

          Variable port v_pos_minus_1 type Integer:

              InStr( File_Name, '-')

          Variable port v_pos_minus_2 type Integer:

              InStr( File_Name, '-', 1, 2)

          Variable (or output) port type String:

              SubStr( File_Name, v_pos_minus_1 + 1, v_pos_minus_2 - v_pos_minus_1 - 1)

          This will return the substring of "File_Name" from the character following the first minus sign up to (but not including) the second minus sign.

           

          If the two minus signs cannot be used as indicators for the position of the date, then please tell us exactly what these file names may consist of.

           

          Regards,

          Nico

          • 2. Re: extract no form string
            SP K Seasoned Veteran

            Thanks Nico,

             

            Not sure why Reg_Extract( File_Name, '[^-]*-(\d+)-.*.txt', 1) is not working it is just giving Null value.

             

            but i used Substring to capture date portion.

             

             

            Thanks

            Nag