Re: Regular Expressions?
- From: "Rad [Visual C# MVP]" <nospam@xxxxxxxxxx>
- Date: Thu, 23 Nov 2006 21:19:57 +0300
Sorry, forgot to context switch!
Here is the code in VB
'
' Create our regex
'
dim r as new Regex("\[(?<Number>.*?)\]")
'
' Setup our capture string
'
dim test as string = "[54x454],[22b6],[885333]"
'
' Get our matches
'
dim m as MatchCollection = r.Matches(test)
'
' Do with them as we will!
'
for i as integer = 0 to m.Count-1
Console.WriteLine(m(i).Groups(1).Value)
next
On Thu, 23 Nov 2006 20:56:46 +0300, "Rad [Visual C# MVP]"
<nospam@xxxxxxxxxx> wrote:
Hey G,--
Try this code:
//
// Create our regex
//
Regex r = new Regex(@"\[(?<Number>.*?)\]");
//
// Setup our capture string
//
string test = @"[54x454],[22b6],[885333]";
//
// Get our matches
//
MatchCollection m = r.Matches(test);
//
// Do with them as we will!
//
for(int i = 0; i<m.Count;i++)
Console.WriteLine(m[i].Groups[1].Value);
On Thu, 23 Nov 2006 12:00:19 -0000, "G .Net" <nodamnspam@xxxxxxxxx>
wrote:
Thanks guys
Looks promising!
Could I bother you again. What if the characters I'm interested are enclosed
in [ and ]. For example,
"[54x454],[22b6],[885333]"
G
"Ken Tucker [MVP]" <vb2ae@xxxxxxxxxxxxx> wrote in message
news:C6B15518-0E76-4900-8671-789EC607E4C4@xxxxxxxxxxxxxxxx
Dim strTest As String = "#54x454#,#22b6#,#885333#"
Dim strNums() As String
strNums = strTest.Replace("#"c, "").Split(","c)
For Each s As String In strNums
Debug.Print(s)
Next
Ken
---------------------------
"G .Net" <nodamnspam@xxxxxxxxx> wrote in message
news:bdadneeMCM9M4_jYnZ2dnUVZ8t2dnZ2d@xxxxxxxxxxxx
Hi
I was wondering if you could help me with the following:
I have a string e.g. "#54x454#,#22b6#,#885333#".
I want to be able to store in an array list, the following from the
string:
54x454
22b6
885333
That is, the items between the hash signs.
I believe this could be done with regular expressions?
Can anybody show me some code to achieve this. By the way, there may be
more than three items.
Thanks in advance
G
Bits.Bytes.
http://bytes.thinkersroom.com
.
- Follow-Ups:
- Re: Regular Expressions?
- From: G .Net
- Re: Regular Expressions?
- References:
- Q: Regular Expressions?
- From: G .Net
- Re: Regular Expressions?
- From: Ken Tucker [MVP]
- Re: Regular Expressions?
- From: G .Net
- Re: Regular Expressions?
- From: Rad [Visual C# MVP]
- Q: Regular Expressions?
- Prev by Date: Re: MICROSOFT ROADMAP FOR VB
- Next by Date: Re: Is VB.NET Stable??
- Previous by thread: Re: Regular Expressions?
- Next by thread: Re: Regular Expressions?
- Index(es):
Relevant Pages
|