Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Regular Expression for Date not working
#1
Solved: 11 Years, 3 Months, 3 Weeks ago
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
Reply
#2
Solved: 11 Years, 3 Months, 3 Weeks ago
I think you can get it on your own... there is some problem with regular exp. It doesn't match the expected string.
Want to fast track your QTP/UFT Learning? Join our UFT Training Course
Reply
#3
Solved: 11 Years, 3 Months, 3 Weeks ago
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
Reply
#4
Solved: 11 Years, 3 Months, 3 Weeks ago
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...
Want to fast track your QTP/UFT Learning? Join our UFT Training Course
Reply
#5
Solved: 11 Years, 3 Months, 3 Weeks ago
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])
Reply
#6
Solved: 11 Years, 3 Months, 3 Weeks ago
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
Reply
#7
Solved: 11 Years, 3 Months, 3 Weeks ago
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
Reply
#8
Solved: 11 Years, 3 Months, 3 Weeks ago
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
Reply
#9
Solved: 11 Years, 3 Months, 3 Weeks ago
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
Reply
#10
Solved: 11 Years, 3 Months, 3 Weeks ago
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
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How to click on a date button? Parthasit033 0 1,940 09-06-2017, 01:49 AM
Last Post: Parthasit033
  Need Any digit in xpath path using Regular expression Priyam 1 3,484 10-05-2016, 11:05 AM
Last Post: Ankur
  Regular expression to read two words in lowercase, uppercase and with and without spa sarahq49 1 3,351 04-09-2015, 01:56 AM
Last Post: sarahq49
  Regular expression and script optimisation Padmavathy 1 3,817 03-30-2015, 11:46 AM
Last Post: supputuri
  Regular expression in descriptive programming testernc 1 16,565 12-08-2014, 06:38 PM
Last Post: anshika.agarwal

Forum Jump:


Users browsing this thread: 2 Guest(s)