Forum Discussion

sindhu10's avatar
sindhu10
Contributor
6 years ago

How to iterate date in text file using regular expression

I am trying to iterate the date inside the text file and want to import the file in my application using test complete,

 

tried using regular expression its not working 

 

For ex: 

30/05/2018,09:30,00:25,Slot2,NH New History-2,03,,07,,Comedy,16,,06,,"Host has to offer.",2016,,,ENG,SGGTY5527,,,25,,,,,,,,,,,,1|2|3,30,VOD,E,,,Y
30/05/2018,11:35,00:25,Slot1,NH New History-1,03,,07,,Comedy,18,,F,,"Host has to offer.",2016,,,ENG,SGGYT5127,,,25,,,,,,,,,,,,1|2|3,15,VOD,M,,,N
30/05/2018,14:30,00:25,Slot3,NH New History-3,03,,07,,Comedy,16,,06,,"Host has to offer.",2016,,,ENG,SGYGT5627,,,25,,,,,,,,,,,,1|2|3,30,VOD,,,,

 

in the above text the date should get replaced by 30/05/2019 for all occurrences .

 

The code i tried :

 s = "Some 20/04/2021 ex 2021/02/21 dfsdkjfdksajsda"     

 

var re =/^(0?[1-9]|[12][0-9]|3[01])[\/](0?[1-9]|1[012])[\/\-]\d{4}$/g;

var m;

while (m = re.exec(s)) {

 

var myDate=new Date(m)

myDate.setFullYear(myDate.getFullYear() + 1);

a=s.replace(m,myDate.toLocaleDateString())

  alert(a);

}

       

 

5 Replies

  • Marsha_R's avatar
    Marsha_R
    Champion Level 3

    What are you trying to do in your test with this iterated date?  Perhaps we can come up with an easier way to do it.

    • sindhu10's avatar
      sindhu10
      Contributor

      Marsha_R

       

      Thanks!

       

      I want to import the file for my test so changing the dates every time before import .

       

      example : if the file has the date : 02/05/2018 , next time it should get incremented by year like 02/05/2019

       

      Please suggest

      • Marsha_R's avatar
        Marsha_R
        Champion Level 3

        Is the date the same for every line in the file?  Perhaps you could use a project variable and read the value from that instead.  It would be a lot easier to increment it there instead of trying to update all those strings.