QTP Forums

Full Version: Regular Expression for Date not working
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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
I think you can get it on your own... there is some problem with regular exp. It doesn't match the expected string.
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
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...
Try this one it will cover 5/2/2008
(0[1-9]|1[012])[//](0[1-9]|[12][0-9]|3[01])[//]200[0-9])
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...

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

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

Thanks
Shashi
Hi,

([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?

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

Thanks,
Akhila
Hi
You can use the below

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
Hi u can use below one
d/m/yyyy
"(\d|[12]\d|3[01])/(\d|1[0-2])/(19|20)\d\d)"

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

This will narrow down the chances of failing

Thanks
VENKATA
(10-30-2008 06:16 AM)Akhila Wrote: [ -> ]Hi,

([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?

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

Thanks,
Akhila


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
Reference URL's