Micro Focus QTP (UFT) Forums
Regular Expression - 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 (/Thread-Regular-Expression--1112)



Regular Expression - rajeshvelur - 10-03-2008

Hi,

I am testing Windows Forms app, with Test Advantage add-in.

Have a question, how to use reg exp for the following:
"10/2/2008 4:24:05 PM"

Thanks
Raj


RE: Regular Expression - kishoreinchennai - 10-03-2008

hi

Do you want to validate the date and time or just to check if it is of the above format.
the Simplest way to do this is :
Code:
Set objRegExpr = CreateObject("VBScript.RegExp")
Environment.Value("LOB")="10/2/2008 4:24:05 PM"
If isdate(Environment.Value("LOB")) Then
    msgbox "true",0
    Else
    msgbox "False",0
End If
Regards


RE: Regular Expression - sandeep n - 10-10-2008

'Just try this for date and i think this is the longest way which i ever saw Big Grin Big Grin
Code:
dim abc,def,ghi,j

abc="10/2/2008 4:24:05 PM"

def=split(abc," ")                 'Split by space  " "

'def(0) will be "10/2/2008"
'def(1) will be "4:24:05"
'def(2) will be "PM"
'again split def(0) by slash

ghi=split(def(0),"/")              'Split def(0) by slash "/"

      j=mid(ghi(2),1,1)      'Here it checks for the 2nd character ie: before "08" & after "2" in the string "2008"
           if j=9 then
                  (^4-9)(0-9)\/ (^3-9)(0-9)\/ 19*(0-9)(^0-7)
           else if j=0 then
                  (^4-9)(0-9)\/ (^3-9)(0-9)\/ 20*(0-9)(0-9)
           else if j=1 then
                  (^4-9)(0-9)\/ (^3-9)(0-9)\/ 21*(0-9)(0-9)
           .
           .
           .
           .        
           .
          else if j=9 then
                  (^4-9)(0-9)\/ (^3-9)(0-9)\/ 29*(0-9)(0-9)        
          end if


in same way try for time def(1)


RE: Regular Expression - sandeep n - 10-10-2008

here no were u r using objregexpr, does that really needed??


RE: Regular Expression - kishoreinchennai - 10-17-2008

yes actually not needed copy paste error :-)


RE: Regular Expression - surya_7mar - 11-29-2008

If you using OR chage the object to regular expressionwth the value below and if it is descriptive use tehe below on the code..

For "10/2/2008 4:24:05 PM"
Regular Exp: "\d?\d/\d?\d/\d\d\d\d \d?\d:\d?\d:\d?\d .M"

or "\d?\d/\d?\d/\d\d\d\d \d?\d:\d?\d:\d?\d AM|\d?\d/\d?\d/\d\d\d\d \d?\d:\d?\d:\d?\d PM"