Regex: Search Result AND Position

The task at hand is to find all the words greater than 1 letter in length that are capitalized AND the position of those words in a line. I am using the search pattern below for what it is worth and it does what I need

I put it all in a loop and find all the instances of capitalized words in the line and I store them in an array. Roughly the code is as below. This all works fine.

… match = re.Search( myLine ) while match isa RegExMatch … result = match.SubExpressionString(0) asCapital.Append(result) … match = re.Search // Get the next match wend

Now I have this array of capitalized words but for my purposes, I also need their position in the line.

I could go through the array asCapital and with multiple uses of InStr I could find the position in the line of all these words that I have found. But this seems a little “inefficient” in that I am effectively searching the line twice. Once with RegEx and then a second time using the found words themselves.

I just wonder if there is something using RegEx alone that provides the answer to both these items: the found words and the positions of those words. I am hoping that if I knew RegEx better, there would be a simpler answer. The Regex has to “know” where it is as if finds these capitalized words so it can progress to the next search in the loop.

Is there something more elegant?

You may find the RegExMatch documentation of particular use for this.
https://documentation.xojo.com/index.php/RegExMatch

Tim was kind enough to direct me to the documentation that explains that the position is provided after a RegEx match (in addition to the matching string itself)

RegExMatch.SubExpressionStartB(matchNumber as Integer) As Integer

The Xojo documentation also advises you around the ever-present zero-based vs 1-based problems that might arise in common use which is nice.

characterPosition = theString.LeftB(aRegExMatch.SubExpressionStartB(matchNumber)).Len + 1