By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,386 Members | 1,676 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,386 IT Pros & Developers. It's quick & easy.

Regex Vb.net question

P: n/a
How Do I use the following auto-generated code from The Regulator?

'------------------------------------------------------------------------------
' <autogenerated>
' This code was generated by a tool.
' Runtime Version: 1.1.4322.2032
'
' Changes to this file may cause incorrect behavior and will be lost if
' the code is regenerated.
' </autogenerated>
'------------------------------------------------------------------------------

Option Strict Off
Option Explicit On
Namespace Regulator

Public Class RegularExpression

Private Sub Test()
Dim regex As String = "^(([a-zA-Z]:)|(\\{2}\w+)\$?)(\\(\w[\w ]*))+\.(txt|TXT)$"
Dim options As System.Text.RegularExpressions.RegexOptions = ((System.Text.RegularExpressions.RegexOptions.Igno rePatternWhitespace Or System.Text.RegularExpressions.RegexOptions.Multil ine) _
Or System.Text.RegularExpressions.RegexOptions.Ignore Case)
Dim reg As System.Text.RegularExpressions.Regex = New System.Text.RegularExpressions.Regex(regex, options)
End Sub
End Class
End Namespace

I've placed this code in it's own file by clicking on Project-->Add New-->Class.

Then from inside another one of my project files I...

Dim MyVariable As New Regulator.RegularExpression

Now what do I have to do to use this expression?

Any help would be greatly appreciated.

Thanks,

Chris

Dec 13 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a


Dim regex As String =
"^(([a-zA-Z]:)|(\\{2}\w+)\$?)(\\(\w[\w ]*))+\.(txt|TXT)$"
Dim options As System.Text.RegularExpressions.RegexOptions =
((System.Text.RegularExpressions.RegexOptions.Igno rePatternWhitespace Or
System.Text.RegularExpressions.RegexOptions.Multil ine) _
Or
System.Text.RegularExpressions.RegexOptions.Ignore Case)
Dim reg As System.Text.RegularExpressions.Regex = New
System.Text.RegularExpressions.Regex(regex, options)

Dim objMatches As
System.Text.RegularExpressions.MatchCollection
Dim objMatch As System.Text.RegularExpressions.Match
objMatches = reg.Matches("your text here", regex)
For Each objMatch In objMatches
Debug.WriteLine(objMatch.Value)
objMatch = Nothing
Next

[]s
Cesar

"Chris" <co***********@nospam.yahoo.com> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
How Do I use the following auto-generated code from The Regulator?

'------------------------------------------------------------------------------
' <autogenerated>
' This code was generated by a tool.
' Runtime Version: 1.1.4322.2032
'
' Changes to this file may cause incorrect behavior and will be lost if
' the code is regenerated.
' </autogenerated>
'------------------------------------------------------------------------------

Option Strict Off
Option Explicit On
Namespace Regulator

Public Class RegularExpression

Private Sub Test()
Dim regex As String =
"^(([a-zA-Z]:)|(\\{2}\w+)\$?)(\\(\w[\w ]*))+\.(txt|TXT)$"
Dim options As System.Text.RegularExpressions.RegexOptions =
((System.Text.RegularExpressions.RegexOptions.Igno rePatternWhitespace Or
System.Text.RegularExpressions.RegexOptions.Multil ine) _
Or
System.Text.RegularExpressions.RegexOptions.Ignore Case)
Dim reg As System.Text.RegularExpressions.Regex = New
System.Text.RegularExpressions.Regex(regex, options)
End Sub
End Class
End Namespace

I've placed this code in it's own file by clicking on Project-->Add
New-->Class.
Then from inside another one of my project files I...
Dim MyVariable As New Regulator.RegularExpression
Now what do I have to do to use this expression?
Any help would be greatly appreciated.
Thanks,
Chris
Dec 13 '05 #2

P: n/a
Hi Cesar,

Thanks for the reply!

When I pasted the code into my project I got a get errors. After doing
whatever I had to do to make the errors go away I just wanted to make sure
that I didn't screw things up

Here is what I have now:

Dim regex As String =
"^(([a-zA-Z]:)|(\\{2}\w+)\$?)(\\(\w[\w ]*))+\.(txt|TXT)$"
Dim options As System.Text.RegularExpressions.RegexOptions = _
((System.Text.RegularExpressions.RegexOptions.Igno rePatternWhitespace
Or _
System.Text.RegularExpressions.RegexOptions.Single line) _
Or System.Text.RegularExpressions.RegexOptions.Ignore Case)

Dim reg As System.Text.RegularExpressions.Regex = New
System.Text.RegularExpressions.Regex(regex, options)

Dim objMatches As System.Text.RegularExpressions.MatchCollection
Dim objMatch As System.Text.RegularExpressions.Match
objMatches = System.Text.RegularExpressions.Regex.Matches("your text
here", regex)

For Each objMatch In objMatches
Debug.WriteLine(objMatch.Value)
objMatch = Nothing
Next

Another question: is this code using the class from my original post? Is
that auto-generated class usful at all or should I not be concerned with it?

Thanks again,

Chris
"Cesar Ronchese" <ronchese_hotmail_dot_com> wrote in message
news:eF*************@TK2MSFTNGP12.phx.gbl...


Dim regex As String =
"^(([a-zA-Z]:)|(\\{2}\w+)\$?)(\\(\w[\w ]*))+\.(txt|TXT)$"
Dim options As System.Text.RegularExpressions.RegexOptions
= ((System.Text.RegularExpressions.RegexOptions.Igno rePatternWhitespace Or
System.Text.RegularExpressions.RegexOptions.Multil ine) _
Or
System.Text.RegularExpressions.RegexOptions.Ignore Case)
Dim reg As System.Text.RegularExpressions.Regex = New
System.Text.RegularExpressions.Regex(regex, options)

Dim objMatches As
System.Text.RegularExpressions.MatchCollection
Dim objMatch As System.Text.RegularExpressions.Match
objMatches = reg.Matches("your text here", regex)
For Each objMatch In objMatches
Debug.WriteLine(objMatch.Value)
objMatch = Nothing
Next

[]s
Cesar

"Chris" <co***********@nospam.yahoo.com> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
How Do I use the following auto-generated code from The Regulator?

'------------------------------------------------------------------------------
' <autogenerated>
' This code was generated by a tool.
' Runtime Version: 1.1.4322.2032
'
' Changes to this file may cause incorrect behavior and will be lost
if
' the code is regenerated.
' </autogenerated>
'------------------------------------------------------------------------------

Option Strict Off
Option Explicit On
Namespace Regulator

Public Class RegularExpression

Private Sub Test()
Dim regex As String =
"^(([a-zA-Z]:)|(\\{2}\w+)\$?)(\\(\w[\w ]*))+\.(txt|TXT)$"
Dim options As System.Text.RegularExpressions.RegexOptions =
((System.Text.RegularExpressions.RegexOptions.Igno rePatternWhitespace Or
System.Text.RegularExpressions.RegexOptions.Multil ine) _
Or
System.Text.RegularExpressions.RegexOptions.Ignore Case)
Dim reg As System.Text.RegularExpressions.Regex = New
System.Text.RegularExpressions.Regex(regex, options)
End Sub
End Class
End Namespace

I've placed this code in it's own file by clicking on Project-->Add
New-->Class.
Then from inside another one of my project files I...
Dim MyVariable As New Regulator.RegularExpression
Now what do I have to do to use this expression?
Any help would be greatly appreciated.
Thanks,
Chris

Dec 13 '05 #3

P: n/a
The first line in my last post should read:

When I pasted the code into my project I got errors.

Sorry about the type-o

Chris

"Chris" <co***********@nospam.yahoo.com> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
Hi Cesar,

Thanks for the reply!

When I pasted the code into my project I got a get errors. After doing
whatever I had to do to make the errors go away I just wanted to make sure
that I didn't screw things up

Here is what I have now:

Dim regex As String =
"^(([a-zA-Z]:)|(\\{2}\w+)\$?)(\\(\w[\w ]*))+\.(txt|TXT)$"
Dim options As System.Text.RegularExpressions.RegexOptions = _

((System.Text.RegularExpressions.RegexOptions.Igno rePatternWhitespace Or _
System.Text.RegularExpressions.RegexOptions.Single line) _
Or System.Text.RegularExpressions.RegexOptions.Ignore Case)

Dim reg As System.Text.RegularExpressions.Regex = New
System.Text.RegularExpressions.Regex(regex, options)

Dim objMatches As System.Text.RegularExpressions.MatchCollection
Dim objMatch As System.Text.RegularExpressions.Match
objMatches = System.Text.RegularExpressions.Regex.Matches("your
text here", regex)

For Each objMatch In objMatches
Debug.WriteLine(objMatch.Value)
objMatch = Nothing
Next

Another question: is this code using the class from my original post? Is
that auto-generated class usful at all or should I not be concerned with
it?

Thanks again,

Chris
"Cesar Ronchese" <ronchese_hotmail_dot_com> wrote in message
news:eF*************@TK2MSFTNGP12.phx.gbl...


Dim regex As String =
"^(([a-zA-Z]:)|(\\{2}\w+)\$?)(\\(\w[\w ]*))+\.(txt|TXT)$"
Dim options As System.Text.RegularExpressions.RegexOptions
= ((System.Text.RegularExpressions.RegexOptions.Igno rePatternWhitespace
Or System.Text.RegularExpressions.RegexOptions.Multil ine) _
Or
System.Text.RegularExpressions.RegexOptions.Ignore Case)
Dim reg As System.Text.RegularExpressions.Regex = New
System.Text.RegularExpressions.Regex(regex, options)

Dim objMatches As
System.Text.RegularExpressions.MatchCollection
Dim objMatch As System.Text.RegularExpressions.Match
objMatches = reg.Matches("your text here", regex)
For Each objMatch In objMatches
Debug.WriteLine(objMatch.Value)
objMatch = Nothing
Next

[]s
Cesar

"Chris" <co***********@nospam.yahoo.com> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
How Do I use the following auto-generated code from The Regulator?

'------------------------------------------------------------------------------
' <autogenerated>
' This code was generated by a tool.
' Runtime Version: 1.1.4322.2032
'
' Changes to this file may cause incorrect behavior and will be lost
if
' the code is regenerated.
' </autogenerated>
'------------------------------------------------------------------------------

Option Strict Off
Option Explicit On
Namespace Regulator

Public Class RegularExpression

Private Sub Test()
Dim regex As String =
"^(([a-zA-Z]:)|(\\{2}\w+)\$?)(\\(\w[\w ]*))+\.(txt|TXT)$"
Dim options As System.Text.RegularExpressions.RegexOptions =
((System.Text.RegularExpressions.RegexOptions.Igno rePatternWhitespace Or
System.Text.RegularExpressions.RegexOptions.Multil ine) _
Or
System.Text.RegularExpressions.RegexOptions.Ignore Case)
Dim reg As System.Text.RegularExpressions.Regex = New
System.Text.RegularExpressions.Regex(regex, options)
End Sub
End Class
End Namespace

I've placed this code in it's own file by clicking on Project-->Add
New-->Class.
Then from inside another one of my project files I...
Dim MyVariable As New Regulator.RegularExpression
Now what do I have to do to use this expression?
Any help would be greatly appreciated.
Thanks,
Chris


Dec 13 '05 #4

P: n/a
The following line:
objMatches = reg.Matches("your text here", regex)

Gives me the following warning:
Access of shared member through an instance; qualifying expression will not
be evaluated

The VB 2005 IDE suggest to change reg.Matches() to Regex.matches

If I accept the change then the warning goes away.

My issue is then what happens to my RegexOptions that I set?

Chris
"Cesar Ronchese" <ronchese_hotmail_dot_com> wrote in message
news:eF*************@TK2MSFTNGP12.phx.gbl...


Dim regex As String =
"^(([a-zA-Z]:)|(\\{2}\w+)\$?)(\\(\w[\w ]*))+\.(txt|TXT)$"
Dim options As System.Text.RegularExpressions.RegexOptions
= ((System.Text.RegularExpressions.RegexOptions.Igno rePatternWhitespace Or
System.Text.RegularExpressions.RegexOptions.Multil ine) _
Or
System.Text.RegularExpressions.RegexOptions.Ignore Case)
Dim reg As System.Text.RegularExpressions.Regex = New
System.Text.RegularExpressions.Regex(regex, options)

Dim objMatches As
System.Text.RegularExpressions.MatchCollection
Dim objMatch As System.Text.RegularExpressions.Match
objMatches = reg.Matches("your text here", regex)
For Each objMatch In objMatches
Debug.WriteLine(objMatch.Value)
objMatch = Nothing
Next

[]s
Cesar

"Chris" <co***********@nospam.yahoo.com> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
How Do I use the following auto-generated code from The Regulator?

'------------------------------------------------------------------------------
' <autogenerated>
' This code was generated by a tool.
' Runtime Version: 1.1.4322.2032
'
' Changes to this file may cause incorrect behavior and will be lost
if
' the code is regenerated.
' </autogenerated>
'------------------------------------------------------------------------------

Option Strict Off
Option Explicit On
Namespace Regulator

Public Class RegularExpression

Private Sub Test()
Dim regex As String =
"^(([a-zA-Z]:)|(\\{2}\w+)\$?)(\\(\w[\w ]*))+\.(txt|TXT)$"
Dim options As System.Text.RegularExpressions.RegexOptions =
((System.Text.RegularExpressions.RegexOptions.Igno rePatternWhitespace Or
System.Text.RegularExpressions.RegexOptions.Multil ine) _
Or
System.Text.RegularExpressions.RegexOptions.Ignore Case)
Dim reg As System.Text.RegularExpressions.Regex = New
System.Text.RegularExpressions.Regex(regex, options)
End Sub
End Class
End Namespace

I've placed this code in it's own file by clicking on Project-->Add
New-->Class.
Then from inside another one of my project files I...
Dim MyVariable As New Regulator.RegularExpression
Now what do I have to do to use this expression?
Any help would be greatly appreciated.
Thanks,
Chris

Dec 13 '05 #5

P: n/a
Sorry for the delay, I was away for a while. I tested the code below and works, try again:
Dim options As System.Text.RegularExpressions.RegexOptions = ((System.Text.RegularExpressions.RegexOptions.Igno rePatternWhitespace Or System.Text.RegularExpressions.RegexOptions.Multil ine) _
Or System.Text.RegularExpressions.RegexOptions.Ignore Case)
Dim regex As String = "^(([a-zA-Z]:)|(\\{2}\w+)\$?)(\\(\w[\w ]*))+\.(txt|TXT)$"
Dim reg As System.Text.RegularExpressions.Regex = New System.Text.RegularExpressions.Regex(regex, options)
Dim objMatches As System.Text.RegularExpressions.MatchCollection
Dim objMatch As System.Text.RegularExpressions.Match

objMatches = reg.Matches("your text here", regex)

For Each objMatch In objMatches
Debug.WriteLine(objMatch.Value)
objMatch = Nothing
Next

About your other question, yes I just copy and paste your original code and implemented the use of Matches collection. Personally, the only thing I don't like The Regulator auto code is variables nomenclatures. The rest is Ok.

[]s
Cesar


"Chris" <co***********@nospam.yahoo.com> wrote in message news:%2****************@tk2msftngp13.phx.gbl...
The following line:
objMatches = reg.Matches("your text here", regex)

Gives me the following warning:
Access of shared member through an instance; qualifying expression will not
be evaluated

The VB 2005 IDE suggest to change reg.Matches() to Regex.matches

If I accept the change then the warning goes away.

My issue is then what happens to my RegexOptions that I set?

Chris


"Cesar Ronchese" <ronchese_hotmail_dot_com> wrote in message
news:eF*************@TK2MSFTNGP12.phx.gbl...


Dim regex As String =
"^(([a-zA-Z]:)|(\\{2}\w+)\$?)(\\(\w[\w ]*))+\.(txt|TXT)$"
Dim options As System.Text.RegularExpressions.RegexOptions
= ((System.Text.RegularExpressions.RegexOptions.Igno rePatternWhitespace Or
System.Text.RegularExpressions.RegexOptions.Multil ine) _
Or
System.Text.RegularExpressions.RegexOptions.Ignore Case)
Dim reg As System.Text.RegularExpressions.Regex = New
System.Text.RegularExpressions.Regex(regex, options)

Dim objMatches As
System.Text.RegularExpressions.MatchCollection
Dim objMatch As System.Text.RegularExpressions.Match
objMatches = reg.Matches("your text here", regex)
For Each objMatch In objMatches
Debug.WriteLine(objMatch.Value)
objMatch = Nothing
Next

[]s
Cesar

"Chris" <co***********@nospam.yahoo.com> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
How Do I use the following auto-generated code from The Regulator?

'------------------------------------------------------------------------------
' <autogenerated>
' This code was generated by a tool.
' Runtime Version: 1.1.4322.2032
'
' Changes to this file may cause incorrect behavior and will be lost
if
' the code is regenerated.
' </autogenerated>
'------------------------------------------------------------------------------

Option Strict Off
Option Explicit On
Namespace Regulator

Public Class RegularExpression

Private Sub Test()
Dim regex As String =
"^(([a-zA-Z]:)|(\\{2}\w+)\$?)(\\(\w[\w ]*))+\.(txt|TXT)$"
Dim options As System.Text.RegularExpressions.RegexOptions =
((System.Text.RegularExpressions.RegexOptions.Igno rePatternWhitespace Or
System.Text.RegularExpressions.RegexOptions.Multil ine) _
Or
System.Text.RegularExpressions.RegexOptions.Ignore Case)
Dim reg As System.Text.RegularExpressions.Regex = New
System.Text.RegularExpressions.Regex(regex, options)
End Sub
End Class
End Namespace

I've placed this code in it's own file by clicking on Project-->Add
New-->Class.
Then from inside another one of my project files I...
Dim MyVariable As New Regulator.RegularExpression
Now what do I have to do to use this expression?
Any help would be greatly appreciated.
Thanks,
Chris


Dec 13 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.