Regex Vb.net question

C

Chris

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.IgnorePatternWhitespace Or System.Text.RegularExpressions.RegexOptions.Multiline) _
Or System.Text.RegularExpressions.RegexOptions.IgnoreCase)
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
 
C

Chris

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.IgnorePatternWhitespace
Or _
System.Text.RegularExpressions.RegexOptions.Singleline) _
Or System.Text.RegularExpressions.RegexOptions.IgnoreCase)

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 said:
Dim regex As String =
"^(([a-zA-Z]:)|(\\{2}\w+)\$?)(\\(\w[\w ]*))+\.(txt|TXT)$"
Dim options As System.Text.RegularExpressions.RegexOptions
= ((System.Text.RegularExpressions.RegexOptions.IgnorePatternWhitespace Or
System.Text.RegularExpressions.RegexOptions.Multiline) _
Or
System.Text.RegularExpressions.RegexOptions.IgnoreCase)
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

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.IgnorePatternWhitespace Or
System.Text.RegularExpressions.RegexOptions.Multiline) _
Or
System.Text.RegularExpressions.RegexOptions.IgnoreCase)
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
 
C

Chris

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 said:
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.IgnorePatternWhitespace Or _
System.Text.RegularExpressions.RegexOptions.Singleline) _
Or System.Text.RegularExpressions.RegexOptions.IgnoreCase)

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 said:
Dim regex As String =
"^(([a-zA-Z]:)|(\\{2}\w+)\$?)(\\(\w[\w ]*))+\.(txt|TXT)$"
Dim options As System.Text.RegularExpressions.RegexOptions
= ((System.Text.RegularExpressions.RegexOptions.IgnorePatternWhitespace
Or System.Text.RegularExpressions.RegexOptions.Multiline) _
Or
System.Text.RegularExpressions.RegexOptions.IgnoreCase)
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

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.IgnorePatternWhitespace Or
System.Text.RegularExpressions.RegexOptions.Multiline) _
Or
System.Text.RegularExpressions.RegexOptions.IgnoreCase)
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
 
C

Cesar Ronchese

Dim regex As String =
"^(([a-zA-Z]:)|(\\{2}\w+)\$?)(\\(\w[\w ]*))+\.(txt|TXT)$"
Dim options As System.Text.RegularExpressions.RegexOptions =
((System.Text.RegularExpressions.RegexOptions.IgnorePatternWhitespace Or
System.Text.RegularExpressions.RegexOptions.Multiline) _
Or
System.Text.RegularExpressions.RegexOptions.IgnoreCase)
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

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.IgnorePatternWhitespace Or
System.Text.RegularExpressions.RegexOptions.Multiline) _
Or
System.Text.RegularExpressions.RegexOptions.IgnoreCase)
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
 
C

Chris

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
 
C

Cesar Ronchese

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.IgnorePatternWhitespace Or System.Text.RegularExpressions.RegexOptions.Multiline) _
Or System.Text.RegularExpressions.RegexOptions.IgnoreCase)
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 said:
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 said:
Dim regex As String =
"^(([a-zA-Z]:)|(\\{2}\w+)\$?)(\\(\w[\w ]*))+\.(txt|TXT)$"
Dim options As System.Text.RegularExpressions.RegexOptions
= ((System.Text.RegularExpressions.RegexOptions.IgnorePatternWhitespace Or
System.Text.RegularExpressions.RegexOptions.Multiline) _
Or
System.Text.RegularExpressions.RegexOptions.IgnoreCase)
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

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.IgnorePatternWhitespace Or
System.Text.RegularExpressions.RegexOptions.Multiline) _
Or
System.Text.RegularExpressions.RegexOptions.IgnoreCase)
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top