Micro Focus QTP (UFT) Forums
Need help with regular expression Please Assist - 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: Need help with regular expression Please Assist (/Thread-Need-help-with-regular-expression-Please-Assist)



Need help with regular expression Please Assist - RA185112 - 02-02-2013

Hi,

I have encountered an issue, where in I am working with Regular Expression.So need help.

String is str1 = "abcrrera 0200******011" , I am trying to use regular exp as the numbers in the string may change.

what is the Patrn that we need to pass?As i have written the code, however i think i am unable to handle "*" spl character in the above string.


Here is the function that i have written. However i am unable to get the pattern? Need help

Code:
Function RegExpTest(patrn ,string)

Dim regEx, Match, Matches

''Create variable.

Set regEx = New RegExp ' Create regular expression.

n = 0

regEx.Pattern =patrn ' Set pattern.

regEx.IgnoreCase = True ' Set case insensitivity.

regEx.Global = True ' Set global applicability.

Set Matches = regEx.Execute(string) ' Execute search.

For Each Match in Matches ' Iterate Matches collection.

RetStr = RetStr & "Match found at position "

MSGBOX RetStr

RetStr = RetStr & Match.FirstIndex & ". Match Value is '"

MSGBOX RetStr

RetStr = RetStr & Match.Value & "'." & vbCRLF

MSGBOX RetStr

If Match.Value = patrn Then

msgbox patrn

msgbox Match.Value

n = n+1

MSGBOX n

End If

Next

RegExpTest = RetStr

MSGBOX RegExpTest

If n >1Then

Reporter.ReportEvent micPass, "Card Accepted text is Added to ER Area ", "Match Text: is" &patrn & " Repeats " & n & " Times"

msgbox patrn & " repeats " & n & "times"

Elseif n=1 Then

msgbox patrn & " repeats " & n & "times"

Reporter.ReportEvent micPass, "test is present", "Match Text: is" &patrn & " Repeats " & n & " Times"

msgbox patrn & " repeats " & n & "times"

Else

Reporter.ReportEvent micFail, "test is not present", "unMatch Text: " & patrn & " Repeats " & n & " Times"

msgbox patrn & " repeats " & n & "times"

End If

End Function

Request you to kindly give a solution to this using reg expression only.


Thanks in advance.


Regards,
Ras


RE: Need help with regular expression Please Assist - RA185112 - 02-07-2013

Any one please kindly assist.


RE: Need help with regular expression Please Assist - Ankesh - 02-14-2013

to treat * as a normal character insetad of special characters,you need to use escape characters (\).

For example
If you want to match 1+1=2, the correct regex is 1\+1=2. Otherwise, the plus sign will have a special meaning.

Regards,
Ankesh


RE: Need help with regular expression Please Assist - basanth27 - 02-14-2013

Sangeethac,
Would you please elaborate? i still dont understand if you want any string on a webtable which starts with qtp then it would be qtp* etc etc...


RE: Need help with regular expression Please Assist - basanth27 - 02-15-2013

Very Interesting. Did you ask him back as to what does he mean by fetching a whole string using regular expression? Does he mean he wants string of those type or something before that string or after that string? Did you ask him these questions? I am sure you did not Else you would have provided me with more details Smile
I am not demotivating you. But honestly, you have to understand not every question asked the way in the interview has a straightforward answer. These are not mathematical questions.
You have to learn to probe the interviewer as well. If you look at the positive side of it, you will see that you are going to learn more and in that you will find the answer. This leads an interview towards a discussion which I think is healthy and if you dont clear in this you will atleast be good for the next interview.
Take it a tip from the guy who has swum across the IT sector. If you still feel that advice is free and Is a waste of your time, My heartfelt apologies Smile

Good Luck with your interviews.