|
-
Oct 19th, 2006, 05:50 AM
#1
Thread Starter
Frenzied Member
[RESOLVED] [2005] Reg Exp help.
Hi.
I need a regular expression to search a string that contains the possible combinations.
C1..C9
D1..D24
Example 1 "C1D2C9"
Example 2 "C1D1D2D6D11" maximum number of 5 combinations.
Thanks in advance.
Jorge.
"The dark side clouds everything. Impossible to see the future is."
-
Oct 19th, 2006, 06:00 AM
#2
Hyperactive Member
Re: [2005] Reg Exp help.
hi,
try this
'===========
([C-D][0-9]){0,5}
'----------
sagar
-
Oct 19th, 2006, 06:34 AM
#3
Thread Starter
Frenzied Member
Re: [2005] Reg Exp help.
I am new to regexp but t though that that .Match class would return all the positions where a match is found but it only returns the 1st position! I have to browse the string myself?
Jorge
"The dark side clouds everything. Impossible to see the future is."
-
Oct 19th, 2006, 07:55 AM
#4
Addicted Member
Re: [2005] Reg Exp help.
You have to loop through the matches:
VB Code:
Dim matchList As New ArrayList
Dim strText As String = "C1D1D2D6D11"
Dim Regex As New Regex("([C-D][0-9]){1,5}", RegexOptions.IgnoreCase)
Dim Mymatches As MatchCollection = Regex.Matches(strText)
For Each FoundMatch As Match In Mymatches
matchList.Add(FoundMatch.Value)
Next
IDE: Visual Studio 2008/2010 - C# | VB.Net
-
Oct 19th, 2006, 11:42 AM
#5
Thread Starter
Frenzied Member
Re: [2005] Reg Exp help.
Hi, there's a litttle problem i tried this
VB Code:
Dim matchList As New ArrayList
Dim strText As String = "D20D21D22D23D24"
Dim Regex As New System.Text.RegularExpressions.Regex("([C-D][0-9]){1,5}")
Dim Mymatches As System.Text.RegularExpressions.MatchCollection = Regex.Matches(strText)
For Each FoundMatch As System.Text.RegularExpressions.Match In Mymatches
matchList.Add(FoundMatch.Value)
''matchList.Add(FoundMatch.Index)
Next
For i = 0 To matchList.Count - 1
Console.WriteLine(matchList(i).ToString)
Next
It outputs
D2
D2
D2
D2
D2
instead of
D20
D21
D22
D23
D24
Any suggestions.
Jorge
"The dark side clouds everything. Impossible to see the future is."
-
Oct 19th, 2006, 12:45 PM
#6
Re: [2005] Reg Exp help.
Do you want the unique combinations? if yes check for it in my signature.
Last edited by VBDT; Oct 19th, 2006 at 12:58 PM.
-
Oct 19th, 2006, 01:30 PM
#7
Addicted Member
Re: [2005] Reg Exp help.
Use this search string instead:
VB Code:
Dim Regex As New Regex("(C[1-9]|(D[1-9])(?!\d)|D1\d|D2[1-4])")
This will only find C1-9 or D1-24 in the string "C0C1C2D1D3D15D0D20D21D22D23D24D25D30"
This is assuming you don't want the other numbers.
Last edited by Isorfir; Oct 19th, 2006 at 01:36 PM.
IDE: Visual Studio 2008/2010 - C# | VB.Net
-
Oct 20th, 2006, 05:13 AM
#8
Thread Starter
Frenzied Member
Re: [2005] Reg Exp help.
Ok, this search expression works pefectly, Thanks.
Jorge
"The dark side clouds everything. Impossible to see the future is."
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|