Need a fancy RegEx

If anyone can figure this out. it would be Kem :slight_smile:

Given 4 discrete strings (none of the a constant)
Given an Index to a postion in another String (call it source)
return the postion of the first of the 4 string that appear in the source string and which of the 4 strings it was

so for example… if the 4 strings were “A”,“B”,“C”,“D”
and the source string was “WXYZCQRNADCB”
and position were 1 then answer would be “C” and 5
if position were 5 then the answer would be “A” and “9”

and return 0 if none of them appear

a super set of Instr if you will

I have a verion using IF and Instr… but it is overly complex with a lot of conditions… I’ll bet there is a simple FAST Regex based method

Use the bar as an “or” operator.


You can tell the RegEx object where to start match and will get back a RegExMatch with the position of the first match it finds after that point.

It shouldn’t be overly complex. RegEx is the definition of complex if you ask me.

Dim S() As String
S.Append a.Text
S.Append b.Text
S.Append c.Text
S.Append d.Text

Dim SS as String = SourceString.Text
Dim SP as Integer = StartPos.Text.CLong+1
Dim Pos As Integer
Dim ReturnString As String
Dim r() as Integer 

r.Append InStr(SP,SS,S(0))
r.Append InStr(SP,SS,S(1))
r.Append InStr(SP,SS,S(2))
r.Append InStr(SP,SS,S(3))
For i As Integer = 0 To 3
  if r(i) > 0 then
    Pos = r(i)
  End If
If pos > 0 Then ReturnString = Mid(SS,Pos,1)

Result.text = Pos.ToText + ", " + ReturnString