Regex doesn't match when test string is in middle of file

C

Chris

Hi Everyone,

I am using a regex to check for a string. When all the file contains is my
test string the regex returns a match, but when I embed the test string in
the middle of a text file a match is never returned.

The string that I give to the regex is one that contains the entire contents
of a text file.

I'm using the multi-line option and I've also tried stripping out the VbCr
and VbLf's and replacing them with an " ", nothing helped.

What am I missing?

Thanks,

Chris
 
C

Chris

Hi Jared,
I'm using Regex Buddy right now for testing. I also already have Expresso,
The Regulator, and the RegEx Designer...I've been going crazy trying to get
some help.

Dim ssnRegex As String = "^(?!000)([0-6]\d{2}|7([0-6]\d|7[012])) ([ -])?
(?!00)\d\d([ -|])? (?!0000)\d{4}$"

Dim options As System.Text.RegularExpressions.RegexOptions =
System.Text.RegularExpressions.RegexOptions.Multiline

Dim oSSNRegex As New Regex(RegExTypes.ssnRegex, RegExTypes.options)

Inside Regex Buddy, or any of the others, if I use their method to import
the text from a test file everything works great and the RegEx returns a
match. However, when I view the debugger in Visual Studio and take a look at
the string I see all of the square like VbCrLf's in with the string that
represents the file I'm testing. If I paste the string that represents the
file I'm testing from the watch list in Visual Studio to Regex Buddy, or any
of the others, the RegEx fails to make a match. Additionally, I've also
tried replacing all of the VbCr and VbLf's with just a blank space " ".

Here is a representation of the filecontents I'm looking at (from inside the
Visual Studio debugger). I've replaced all of the actual VbCrLf's with
readable values:

FileContents = "Microsoft (R) Windows Script Host Version 5.6vbCrLfCopyright
(C) Microsoft Corporation 1996-2001. All rights reserved.vbCrLfvbCrLfUsing
Path: \\WKS3A\c$\Documents and Settings\Diana.CFLLAW\Application
Data\Express\SendvbCrLfResults for: WKS3A - Diana.CFLLAWvbCrLfvbCrLfThe MEAN
dictation file size: 0 MBvbCrLfvbCrLfLargest File: 0 MBvbCrLf1 files
considered in
average.vbCrLfvbCrLf============================================vbCrLfvbCrLfvbCrLfUsing
Path: \\WKS5A\c$\Documents and Settings\Diana.CFLLAW\Application
Data\Express\SendvbCrLfResults for: WKS5A - Diana.CFLLAWvbCrLfvbCrLfThe MEAN
dictation file size: 0 MBvbCrLfvbCrLfLargest File: 0 MBvbCrLf1 files
considered in
average.vbCrLfvbCrLf============================================vbCrLfvbCrLf134
73 9834vbCrLfvbCrLfvbCrLf"

Does this information help in figuring out what I'm doing wrong?

Thanks,

Chris
 
L

Lars Graeve

Hi

Chris said:
Hi Jared,
I'm using Regex Buddy right now for testing. I also already have Expresso,
The Regulator, and the RegEx Designer...I've been going crazy trying to
get some help.

Dim ssnRegex As String = "^(?!000)([0-6]\d{2}|7([0-6]\d|7[012])) ([ -])?
(?!00)\d\d([ -|])? (?!0000)\d{4}$"

Your problem is here. You should define the regular expression like this:
Dim ssnRegex As String = "(?!000)([0-6]\d{2}|7([0-6]\d|7[012])) ([ -])?
(?!00)\d\d([ -|])? (?!0000)\d{4}"

^ and $ defines the start and end of the text to check, not the start and
end of the reg. expression.
Dim options As System.Text.RegularExpressions.RegexOptions =
System.Text.RegularExpressions.RegexOptions.Multiline

Dim oSSNRegex As New Regex(RegExTypes.ssnRegex, RegExTypes.options)

Inside Regex Buddy, or any of the others, if I use their method to import
the text from a test file everything works great and the RegEx returns a
match. However, when I view the debugger in Visual Studio and take a look
at the string I see all of the square like VbCrLf's in with the string
that represents the file I'm testing. If I paste the string that
represents the file I'm testing from the watch list in Visual Studio to
Regex Buddy, or any of the others, the RegEx fails to make a match.
Additionally, I've also tried replacing all of the VbCr and VbLf's with
just a blank space " ".

Here is a representation of the filecontents I'm looking at (from inside
the Visual Studio debugger). I've replaced all of the actual VbCrLf's with
readable values:

FileContents = "Microsoft (R) Windows Script Host Version
5.6vbCrLfCopyright (C) Microsoft Corporation 1996-2001. All rights
reserved.vbCrLfvbCrLfUsing Path: \\WKS3A\c$\Documents and
Settings\Diana.CFLLAW\Application Data\Express\SendvbCrLfResults for:
WKS3A - Diana.CFLLAWvbCrLfvbCrLfThe MEAN dictation file size: 0
MBvbCrLfvbCrLfLargest File: 0 MBvbCrLf1 files considered in
average.vbCrLfvbCrLf============================================vbCrLfvbCrLfvbCrLfUsing
Path: \\WKS5A\c$\Documents and Settings\Diana.CFLLAW\Application
Data\Express\SendvbCrLfResults for: WKS5A - Diana.CFLLAWvbCrLfvbCrLfThe
MEAN dictation file size: 0 MBvbCrLfvbCrLfLargest File: 0 MBvbCrLf1 files
considered in
average.vbCrLfvbCrLf============================================vbCrLfvbCrLf134
73 9834vbCrLfvbCrLfvbCrLf"

Does this information help in figuring out what I'm doing wrong?

Thanks,

Chris

Lars
 
C

Chris

Thanks Lars!!!

That worked

Chris


Lars Graeve said:
Hi

Chris said:
Hi Jared,
I'm using Regex Buddy right now for testing. I also already have
Expresso, The Regulator, and the RegEx Designer...I've been going crazy
trying to get some help.

Dim ssnRegex As String = "^(?!000)([0-6]\d{2}|7([0-6]\d|7[012])) ([ -])?
(?!00)\d\d([ -|])? (?!0000)\d{4}$"

Your problem is here. You should define the regular expression like this:
Dim ssnRegex As String = "(?!000)([0-6]\d{2}|7([0-6]\d|7[012])) ([ -])?
(?!00)\d\d([ -|])? (?!0000)\d{4}"

^ and $ defines the start and end of the text to check, not the start and
end of the reg. expression.
Dim options As System.Text.RegularExpressions.RegexOptions =
System.Text.RegularExpressions.RegexOptions.Multiline

Dim oSSNRegex As New Regex(RegExTypes.ssnRegex, RegExTypes.options)

Inside Regex Buddy, or any of the others, if I use their method to import
the text from a test file everything works great and the RegEx returns a
match. However, when I view the debugger in Visual Studio and take a look
at the string I see all of the square like VbCrLf's in with the string
that represents the file I'm testing. If I paste the string that
represents the file I'm testing from the watch list in Visual Studio to
Regex Buddy, or any of the others, the RegEx fails to make a match.
Additionally, I've also tried replacing all of the VbCr and VbLf's with
just a blank space " ".

Here is a representation of the filecontents I'm looking at (from inside
the Visual Studio debugger). I've replaced all of the actual VbCrLf's
with readable values:

FileContents = "Microsoft (R) Windows Script Host Version
5.6vbCrLfCopyright (C) Microsoft Corporation 1996-2001. All rights
reserved.vbCrLfvbCrLfUsing Path: \\WKS3A\c$\Documents and
Settings\Diana.CFLLAW\Application Data\Express\SendvbCrLfResults for:
WKS3A - Diana.CFLLAWvbCrLfvbCrLfThe MEAN dictation file size: 0
MBvbCrLfvbCrLfLargest File: 0 MBvbCrLf1 files considered in
average.vbCrLfvbCrLf============================================vbCrLfvbCrLfvbCrLfUsing
Path: \\WKS5A\c$\Documents and Settings\Diana.CFLLAW\Application
Data\Express\SendvbCrLfResults for: WKS5A - Diana.CFLLAWvbCrLfvbCrLfThe
MEAN dictation file size: 0 MBvbCrLfvbCrLfLargest File: 0 MBvbCrLf1 files
considered in
average.vbCrLfvbCrLf============================================vbCrLfvbCrLf134
73 9834vbCrLfvbCrLfvbCrLf"

Does this information help in figuring out what I'm doing wrong?

Thanks,

Chris

Lars
 

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