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.
Printable View
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.
hi,
try this
'===========
([C-D][0-9]){0,5}
'----------
sagar
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
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
Hi, there's a litttle problem i tried this
It outputsVB 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
D2
D2
D2
D2
D2
instead of
D20
D21
D22
D23
D24
Any suggestions.
Jorge
Do you want the unique combinations? if yes check for it in my signature.
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.
Ok, this search expression works pefectly, Thanks.
Jorge