RE: Getting only numbers instead of values when using regular expression groups in Visual Basic 2008 express

Hi Ken,
I want to extract different parts of the match. This is why I have made
groups. So, I want to say something like firstName=m.groups("fname").value
and get the first name of the employee. 

Pranav
-----Original Message-----
From: programmingblind-bounce@xxxxxxxxxxxxx
[mailto:programmingblind-bounce@xxxxxxxxxxxxx] On Behalf Of Ken Perry
Sent: Friday, May 30, 2008 9:07 PM
To: programmingblind@xxxxxxxxxxxxx
Subject: RE: Getting only numbers instead of values when using regular
expression groups in Visual Basic 2008 express



Ok ignore that last answer.  I just looked at how the regex stuff works I am
wondering why you did the  Dim group etc.  I just tried your code using  the
following line to print out the match:

Console.WriteLine(String.Format("Value {0}", M.Value))

It writes out what it matched like that so if you tell me what you were
trying to do with the dim as group then I can probably tell you how to do
it.

Ken
 

-----Original Message-----
From: programmingblind-bounce@xxxxxxxxxxxxx
[mailto:programmingblind-bounce@xxxxxxxxxxxxx] On Behalf Of Ken Perry
Sent: Friday, May 30, 2008 7:50 AM
To: programmingblind@xxxxxxxxxxxxx
Subject: RE: Getting only numbers instead of values when using regular
expression groups in Visual Basic 2008 express


You need to change your code to use .text rather than .value I think. .

Ken 

-----Original Message-----
From: programmingblind-bounce@xxxxxxxxxxxxx
[mailto:programmingblind-bounce@xxxxxxxxxxxxx] On Behalf Of Pranav Lal
Sent: Friday, May 30, 2008 1:58 AM
To: programmingblind@xxxxxxxxxxxxx
Subject: Getting only numbers instead of values when using regular
expression groups in Visual Basic 2008 express

Hi all,

I have a regular expression in visual basic .net 2008. I am using it to
validate the file names of reports I recieve. I want to use groups in
regular expressions to extract information from the file name.
Whenever I access any item of the groups collection though I can only see a
number. I see no names.

My regular expression is as follows.
(?<fName>\w)+_(?<lName>\w)+\-(\w|\D)+to(\w|\d)+_(?<projectName>\w)+\.xls$

my test string looks like
Pranav_Lal-25To30May2008_vita.xls

Any one any ideas? I am posting the full source of the test program below.

Pranav
Imports System.Text.RegularExpressions

Module Module1

    Sub Main()
        Dim rString As String =
"(?<fName>\w)+_(?<lName>\w)+\-(\w|\D)+to(\w|\d)+_(?<projectName>\w)+\.xls$"

        Try
            Dim TestRegex As Regex = New Regex(rString,
RegexOptions.IgnoreCase)

            Dim S As String = "pranav_lal-12To23April2008_veta.xls"

            Dim M As Match = TestRegex.Match(S)
            If M.Success Then
                Console.WriteLine("ok")
            Else
                Console.WriteLine("error")

            End If
            Dim groups As GroupCollection = M.Groups
            Console.WriteLine(groups.Item(1).Value)

        Catch x As ArgumentException
            Console.WriteLine(x.ToString)
        End Try
        Console.WriteLine("Hit <enter> to exit...")

        Console.ReadLine()


    End Sub
End Module
__________
View the list's information and change your settings at
http://www.freelists.org/list/programmingblind

__________
View the list's information and change your settings at
http://www.freelists.org/list/programmingblind

__________
View the list's information and change your settings at 
http://www.freelists.org/list/programmingblind

__________
View the list's information and change your settings at 
http://www.freelists.org/list/programmingblind

Other related posts: