B2Ben
Well-known member
- Joined
- Aug 17, 2006
- Messages
- 52
- Programming Experience
- Beginner
Here's a simplified example of what I'm working with:
What I want to do:
- ignore zero-or-more non-matching characters at the beginning (the "xx")
- extract the first occurance of something that looks like A##B, where ## is a two-digit number
The problem:
In the above example, the value returned is actually the last occurrance. Specifically, "A03B". I wanted to get "A01B".
Can anybody help me learn how to get the first occurance that I want?
Thanks!
VB.NET:
'Imports System.Text.RegularExpressions
Dim RE As RegEx
Dim Text As String = "xxA01BA02BA03B"
RE = New Regex("^(.*)(A[0-9][0-9]B)") 'The Pattern
Dim Extract As String = RE.Replace(Text, "$2")
MsgBox(Extract)
- ignore zero-or-more non-matching characters at the beginning (the "xx")
- extract the first occurance of something that looks like A##B, where ## is a two-digit number
The problem:
In the above example, the value returned is actually the last occurrance. Specifically, "A03B". I wanted to get "A01B".
Can anybody help me learn how to get the first occurance that I want?
Thanks!
Last edited by a moderator: