I am facing an OutOfBounds exception. The solution probably is very simple, but I cannot wrap my head around it

DIM RXMatches AS RegExMatch = MySuperDuperRegExObject.Search(MySuperDuperRegExSearchString) DIM Parameters AS NEW Dictionary FOR m AS Integer = 1 to RXMatches.SubExpressionCount Parameters.Value(RXMatches.SubExpressionString(m)) = TRUE //<-- Here getting the OOB exception NEXT

In the debugger I can see that RXMatches.SubExpressionCount equals 2.

Maybe: FOR m AS Integer = 0 to RXMatches.SubExpressionCount - 1

What happen when you make one less: FOR m AS Integer = 1 to RXMatches.SubExpressionCount - 1

Just to make sure you don’t count to much

There we go, it has bitten me again. Though SubExpressionString is 0-based, the 0-element contains the full match. The individual matches start at position 1 - but 0 is counted in SubExpressionCount as well. Grrr.