Micro Focus QTP (UFT) Forums
Regular Expression for Date not working - Printable Version

+- Micro Focus QTP (UFT) Forums (https://www.learnqtp.com/forums)
+-- Forum: Micro Focus UFT (earlier known as QTP) (https://www.learnqtp.com/forums/Forum-Micro-Focus-UFT-earlier-known-as-QTP)
+--- Forum: UFT / QTP Regular Expressions (https://www.learnqtp.com/forums/Forum-UFT-QTP-Regular-Expressions)
+--- Thread: Regular Expression for Date not working (/Thread-Regular-Expression-for-Date-not-working)



Regular Expression for Date not working - qtplearner08 - 05-02-2008

Hello,

I'm very new to QTP and just started going through the QTP Tutorial with comes with QTP 9.2 software. Right now I'm reading Lesson 7.

I followed exactly what is been asked to do in the lesson regular expression for date.

[0-1][0-9]/[0-3][0-9]/200[0-9] - This instructs QuickTest to check that each character in the selected text matches the number-range format defined by the regular expression. The expression checks for the following format: MM/DD/200Y.

But when i run the test it fails.

Test Results
------------
Text Checkpoint "CheckExpectedText": Failed

Date and Time: 5/2/2008 - 10:40:17

Checkpoint Timeout: Waited 5 seconds out of a possible 5 seconds

Details

Text Checkpoint: captured "5/2/2008" between San Francisco and SELECT , expected "[0-1][0-9]/[0-3][0-9]/200[0-9]"
Regular Expression : ON
Match case: OFF
Exact match: OFF
Ignore spaces: ON

Can you please tell me what's going wrong and also how to debug such issues? Thanks in advance


RE: Regular Expression for Date not working - Ankur - 05-02-2008

I think you can get it on your own... there is some problem with regular exp. It doesn't match the expected string.


RE: Regular Expression for Date not working - qtplearner08 - 05-02-2008

Hello Ankur,

thanks for your reply, but i tried many timngs and still not able to find out what's worng. can you please let me know what's exactly the problem?

Many Thanks
Shashi


RE: Regular Expression for Date not working - Ankur - 05-02-2008

ok here is something you can work on... Your app doesn't append 0 when month <10 and date part < 10 so tweak the reg ex a little...as of now your reg ex only works when date is in the format 05/02/2008 and not 5/2/2008...

let us know how it goes...


RE: Regular Expression for Date not working - newqtp - 05-03-2008

Try this one it will cover 5/2/2008
Code:
(0[1-9]|1[012])[//](0[1-9]|[12][0-9]|3[01])[//]200[0-9])



RE: Regular Expression for Date not working - qtplearner08 - 05-07-2008

Thanks a lot for your reply

Since the date format is 5/7/2008 i had to remove 0 from the below string and it worked nicely...

Code:
(0[1-9]|1[012])[//](0[1-9]|[12][0-9]|3[01])[//]200[0-9])

so the reg expression is used is
Code:
([1-9]|1[012])[//]([1-9]|[12][0-9]|3[01])[//](200[0-9])

Thanks
Shashi


RE: Regular Expression for Date not working - Akhila - 10-30-2008

Hi,

Code:
([1-9]|1[012])[//]([1-9]|[12][0-9]|3[01])[//](200[0-9])

In the above expression Can we replace double slash [//] with single slash /

I wondering whether below expression is valid or not. If not why?

Code:
([1-9]|1[012])/([1-9]|[12][0-9]|3[01])/(200[0-9])

Thanks,
Akhila


RE: Regular Expression for Date not working - surya_7mar - 11-29-2008

Hi
You can use the below

Code:
For MM/DD/YYYY        \d\d/\d\d/\d\d\d\d
For M/D/YYYY             \d?\d/\d?\d/\d\d\d\d
     ? for 0 or 1
      * for 0 or more
      + for 1 or more



RE: Regular Expression for Date not working - VENKATAREDDY_M - 02-03-2009

Hi u can use below one
d/m/yyyy
Code:
"(\d|[12]\d|3[01])/(\d|1[0-2])/(19|20)\d\d)"

m/d/yyyy
Code:
"(\d|1[0-2])/(\d|[12]\d|3[01])/(19|20)\d\d)"

This will narrow down the chances of failing

Thanks
VENKATA


RE: Regular Expression for Date not working - papu - 03-10-2009

Yes I think we can.bcz forward slash(/) does not have any special meaning as that of backslsh(\).In the code ([1-9]|1[012])[//]([1-9]|[12][0-9]|3[01])[//](200[0-9]) i think it takes one / from [//] ,hence working fine.

plz corect if am wrong