Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Regular Expression
#1
Solved: 11 Years, 4 Months, 4 Weeks ago
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
Reply
#2
Solved: 11 Years, 4 Months, 4 Weeks ago
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
Reply
#3
Solved: 11 Years, 4 Months, 4 Weeks ago
'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)
Reply
#4
Solved: 11 Years, 4 Months, 4 Weeks ago
here no were u r using objregexpr, does that really needed??
Reply
#5
Solved: 11 Years, 4 Months, 4 Weeks ago
yes actually not needed copy paste error :-)
Reply
#6
Solved: 11 Years, 4 Months, 4 Weeks ago
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"
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Need Any digit in xpath path using Regular expression Priyam 1 3,520 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,400 04-09-2015, 01:56 AM
Last Post: sarahq49
  Regular expression and script optimisation Padmavathy 1 3,865 03-30-2015, 11:46 AM
Last Post: supputuri
  Regular expression in descriptive programming testernc 1 16,647 12-08-2014, 06:38 PM
Last Post: anshika.agarwal
  need a regular expression. anu05446 0 3,144 11-26-2014, 03:00 PM
Last Post: anu05446

Forum Jump:


Users browsing this thread: 1 Guest(s)