Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Need help with regular expression Please Assist
#1
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
Reply
#2
Any one please kindly assist.
Reply
#3
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
Reply
#4
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...
Basanth
Give a fish to a man and you feed him for a day..Teach a man how to fish and you feed him for life.
Reply
#5
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.
Basanth
Give a fish to a man and you feed him for a day..Teach a man how to fish and you feed him for life.
Reply


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

Forum Jump:


Users browsing this thread: 1 Guest(s)