Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
regex works but how do i return the found string to a variable
#1
Solved: 11 Years, 4 Months, 3 Weeks ago
Maybe a simple question, so apologies in advance.

I have the following:

Code:
response ="blablahTO-001-A-01blahblablah"

Set oRegExp = New RegExp
oRegExp.IgnoreCase = True
oRegExp.Global=False
oRegExp.Pattern="([A-Z]{2})-([0-9]{3})-([A-Z]{1})-([0-9]{2})"

Msgbox oRegExp.Test(response)

I get a popup saying that it is found

i presume that the correct way to get the string is something like

Code:
string = oRegExp.Test(response)
this sets string to true, but i want string to be set to TO-001-A-01

but I don't know which function will return the found pattern?

Does anyone know how to assign the found pattern to the variable?
Reply
#2
Solved: 11 Years, 4 Months, 3 Weeks ago
Ok I managed to get it to work using the following I found on the net:

Code:
Dim re, testresults, showresults

Set re = new regexp
re.Pattern = "([A-Z]{2})-([0-9]{3})-([A-Z]{1})-([0-9]{2})"
re.Global = true
re.IgnoreCase = true

set testresults = re.Execute(response)
For each match in testresults
    showresults = showresults + match.value
Next

msgbox showresults

Unfortunately I didn't realize in the string i was searching there are 28 separate matches for that search which are all valid but all different.

I just need the very last instance of the match for my purposes.

Does anyone know what the regex is for this?

I am a bit new to regex


Reply
#3
Solved: 11 Years, 4 Months, 3 Weeks ago
I managed to solve the issue by using the string function right to cut down the string. I then used the regex to search for that pattern.

i bet you could do this with regex to match the last instance, please let me know if it is possible, as my code is a bit of a beginners messy code Smile
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  WebElement not found in OR mv8167 6 6,035 03-27-2012, 09:10 PM
Last Post: mv8167
  ReGex not working for Java Items jimrazak 0 2,207 02-23-2012, 06:17 PM
Last Post: jimrazak
  Return the last number of “Test” mv8167 4 3,758 02-07-2012, 03:40 AM
Last Post: mv8167
  Turn Off RegEx mv8167 4 4,728 09-27-2011, 10:20 PM
Last Post: mv8167
  QTP 9.2 RegEx issue ashv 2 3,838 02-20-2011, 12:48 PM
Last Post: ashv

Forum Jump:


Users browsing this thread: 1 Guest(s)