Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Parsing with regular expressions

Status
Not open for further replies.

transparent

Programmer
Sep 15, 2001
333
GB
Anybody have any idea how to do the following:

I have some text such as:

text text text <micrositeIMG23IMGmicrosite> text text text
text text text text text text text text text <micrositeIMG31IMGmicrosite> text text text text text text

I need to be able to get the numbers 23, and 31 out of these strings using regular expressions.

Cheers
 
One way is to use INSTR and MID fuctions.

Dim MyPos1, MyPos2, MyText, MySrch1, MySrch2
MyPos1 = 1
MyPos2 = 1
MyText = &quot;text text text <micrositeIMG23IMGmicrosite> text text text &quot;
MyText = MyText & &quot;text text text text text text text text text <micrositeIMG31IMGmicrosite> text text text text text text&quot;
MySrch1 = &quot;<micrositeIMG&quot;
MySrch2 = &quot;IMGmicrosite>&quot;
While InStr(MyPos1, MyText, MySrch1, 1) + Len(MySrch1) >= MyPos1
MyPos1 = InStr(MyPos2, MyText, MySrch1, 1) + Len(MySrch1)
If MyPos1 Then
MyPos2 = InStr(MyPos1, MyText, MySrch2, 1)
MsgBox Mid(MyText, MyPos1, MyPos2 - MyPos1)
MyPos2 = MyPos2 + 1
End If
Wend
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top