Regular Expression about date

Source: Internet
Author: User

After reading the regular expression learning and sharing of Qiong xiangmm, I remembered that I had learned the regular expression in the past and shared it with me.

I remember the example of the Regular Expression of date in the course of qtp, that is, the regular expression method is used to check the time: month, day, or year, but the test often fails. The expression provided in the example is [0-1] [0-9]/[0-3] [0-9]/200 [0-9]. When the month and date of the time are selected as single digits, no 0 is displayed before the date on the ticket booking page, causing the test to fail.

Problem Analysis:
After the checkpoint is set, the format should be 06/03/2007, and the actual captured format is 6/3/2007. After checking, it is found that if the month and date of the time are not single digits, for example, if the selected time is 10/10/2007, the test is successful.

The checkpoint settings in the example are incorrect. You need to modify the expression.

There are several ways to modify a regular expression:
1. [0-1] {0 ,}[ 0-9]/[0-3] {0 ,}[ 0-9]/200 [0-9]
2. [0-1] {0, 1} [0-9]/[0-3] {0, 1} [0-9]/200 [0-9]
3. [1] {0,} [0-9]/[1-3] {0,} [0-9]/200 [0-9]
4. [1] {0, 1} [0-9]/[1-3] {0, 1} [0-9]/200 [0-9]

Explanation:
[0-1] {0,} indicates the number in parentheses, that is, the number in the range of 0 to 1. 0 to any time is allowed. However, this representation is not suitable. If the month and date are displayed as three or more digits, no error is found.
[0-1] {0, 1} indicates that 0 or a number is allowed. This type of representation strictly specifies the range and display number. If it is not present, it indicates that this month is a single digit and there are no ten digits. This method can be used to indicate whether the previous 0 is omitted in an uncertain program.
[1] {0, 1} indicates that either 1 or 1 may appear. This is also possible. If there is 1, it means that the month is ten digits.

 

Save the modification and run it again. The test passes.

However, it is worth noting that in qtp, if you use a regular expression to check the time, you can only check its format. The selected date cannot be consistent with the displayed date.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.