Right! Stop that! It's silly...and a bit suspect I think... </Monty Python>
So I've got the unique IDs for the two windows into an array, but now I need to tell which is which. As I said before, information in the URLs for each window holds the key:
https://intranet.corporate.com/InquiryWeb/accountInquiryAction.do https://intranet.corporate.com/BillingWeb/requestForOutput.doNo problem, just SubStr out the pertinent part, right? If only it were that easy...one fun surprise the application provides every now and again is that it loses its secure designation (yikes!):
http://The prospect of putting in something like a gazillion if/else statements to accommodate this one nifty little quirk is not on my agenda of fun. But RegEx will have a solution for us now, won't it?
Dealing with the http with an optional s is easy:
Now I just need to match every character up to the next dash:
And capturing only the "word" characters in a subpattern after that dash should get me the information I need:
And if you run that pattern against either of our URLs you will be delighted to find that you are WRONG.
Yet again, I led you down the wrong path. Instead of capturing this text from our URLs:
InquiryWeb BillingWebOur statement will instead capture this text:
accountInquiryAction requestForOutputHow come? A behavior that was previously touched upon but not explored until now: greed.
If you've kept the RegEx Quick Reference handy, you'll see that some of our match characters (asterisk, question mark, plus, and min/max) are by default greedy or, in other words, they will continue to match characters up to the last possible match that will still satisfy the pattern. So where we wanted this portion of our statement:
To stop matching here:
https://intranet.corporate.com/The greed of the asterisk dictated that matching to the next slash would still satisfy the pattern of our statement, so it stopped matching here:
https://intranet.corporate.com/InquiryWeb/So how do we stop greed? A global economic depression followed by a mass implementation of socialist government policies at the national level would be helpful but in our case (focus!) the cure is question mark, which causes any of the aforementioned greedy characters that directly precede it to stop matching at the first match encountered. So this:
Ungreedifies our statement so it matches only this:
https://intranet.corporate.com/Gotta love that question mark. I made up that word up by the way, ungreedify™ (it's trademarked now, watch yourselves!). ANYWAY, now let's review our correctly working RegEx statement in its entirety:
And now we turn the controls over to RegExMatch. The manual shows RegExMatch being used to yield the position of our match, but it doesn't have to be used that way. We can also use it strictly for the purpose of saving a subpattern to a variable, and in our case that's exactly what we need:
So now all we have to do is assign each unique ID in the window array to a group based on the contents of the variable:
Hopefully some of you who are glued to the manual have caught what I'm up to because if you didn't, trying to make this code work is gonna suck. I'll let the manual take over:
If any capturing subpatterns are present inside NeedleRegEx, their matches are stored in an array whose base name is OutputVar. For example, if the variable's name is Match, the substring that matches the first subpattern would be stored in Match1, the second would be stored in Match2, and so on.
So SubPat isn't a variable, it's an array. Let's make it go:
For our next lesson, we'll try something slightly more complex and extract several pieces of data from one statement using RegExMatch.