Got more questions? Find advice on: ASP | SQL | XML | Windows
in Search
Welcome to RegexAdvice Sign in | Join | Help

How to check if a date appears twice in a line of text

Last post 11-21-2008, 4:03 AM by hiro_protagonist. 4 replies.
Sort Posts: Previous Next
  •  11-20-2008, 1:22 PM 48570

    How to check if a date appears twice in a line of text

    Hi all,

     

    I searched for this in the forum, but nothing covered this exactly. I am trying to find lines in a file which contain a date (the date format is yy/mm/dd) twice - these lines are no good and I need to investigate them further. In between those dates can be anything, I don't care what is in between. I tried this:

    ([0-9]{2}/(0?[1-9]|1[012])/(0?[1-9]|[12][0-9]|3[01])){2}.*$

    but that didn't give me the result I was hoping for. Can someone point me in the right direction ?

     

    Thanks in advance ! 

    hiro 

    Filed under:
  •  11-20-2008, 2:54 PM 48580 in reply to 48570

    Re: How to check if a date appears twice in a line of text

    (?=.*\d\d/\d\d/\d{4}.*\d\d/\d\d/\d{4}).*

    test
    test 11/11/1111
    test 11/11/1111 test 11/11/1111
    test 11/11/1111
    test
    test 11/11/1111 test 11/11/1111 test 11/11/1111

  •  11-20-2008, 4:09 PM 48584 in reply to 48580

    Re: How to check if a date appears twice in a line of text

    OK I'm reading this question differently than ddrudik so my quesion is to the OP.

    Are you checking to see if there are two dates  in a line, or to see if the same date is in the line twice?  I took it to be the latter.

    If so my suggested pattern is

    ((?:\d\d/){2}\d{2}).+?\1.*

     Next time please follow the Posting Guidelines http://regexadvice.com/forums/thread/47451.aspx and provide a sample of your real data if possible. It helps in understanding the problem


    Michael

    "In theory, theory and practice are the same. In practice, they are not."
    Albert Einstein
  •  11-21-2008, 4:00 AM 48616 in reply to 48584

    Re: How to check if a date appears twice in a line of text

    mash,

    You are right - apologies for forgetting to post a sample. Here it is, a sample from the file:

    ********,001,08/10/01,07:53,999,39754,000000003,10,246205,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1500,0,774,
    ********,001,08/10/01,07:53,999,39754,000000004,10,257442,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,295,0,0,
    ********,001,08/10/01,07:53,999,39755,000000001,01,999,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,
    ********,001,08/10/01,07:53,999,39755,000000002,10,256053,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,6000,0,3500,

    The problem is that I am concatenating the file from many smaller files (all of the same format) and somewhere, the concatenation must have gone wrong because a date appears twice in one line. It could be the same date, or a different date (I am fairly sure it would be the same date that appears twice in that line but no way to be certain...)
    The lines always end in a comma.

     

    Thank you very much for your time in helping me with this problem.
     

    hiro 

  •  11-21-2008, 4:03 AM 48617 in reply to 48580

    Re: How to check if a date appears twice in a line of text

    Thank you ddrudik !

     

    That's what I need (except the format is yy/mm/dd but I think my regex knowledge, rudimentary though it is, should be good enough to modify =)

     

    Thanks again,

    hiro 

View as RSS news feed in XML