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

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

P: n/a
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
Jul 29 '06 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Chris,
Without posting your expression it would be impossible to answer your
question. I would recommend downloading RegEx Designer.Net by Chris Sells.
It is an excellent tool for testing your expressions.

Attached is the GotDotNet workspace url.
http://www.gotdotnet.com/workspaces/...7-2ed2df2504a9

Look at Chris' site for a screenshot.
http://www.sellsbrothers.com/tools/#regexd

Jared

"Chris" wrote:
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
Jul 29 '06 #2

P: n/a
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.Multil ine

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

"Jared" <Ja***@discussions.microsoft.comwrote in message
news:9C**********************************@microsof t.com...
Chris,
Without posting your expression it would be impossible to answer your
question. I would recommend downloading RegEx Designer.Net by Chris
Sells.
It is an excellent tool for testing your expressions.

Attached is the GotDotNet workspace url.
http://www.gotdotnet.com/workspaces/...7-2ed2df2504a9

Look at Chris' site for a screenshot.
http://www.sellsbrothers.com/tools/#regexd

Jared

"Chris" wrote:
>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

Jul 29 '06 #3

P: n/a
Hi

"Chris" <co***********@nospam.yahoo.comschrieb im Newsbeitrag
news:u4**************@TK2MSFTNGP06.phx.gbl...
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.Multil ine

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

"Jared" <Ja***@discussions.microsoft.comwrote in message
news:9C**********************************@microsof t.com...
>Chris,
Without posting your expression it would be impossible to answer your
question. I would recommend downloading RegEx Designer.Net by Chris
Sells.
It is an excellent tool for testing your expressions.

Attached is the GotDotNet workspace url.
http://www.gotdotnet.com/workspaces/...7-2ed2df2504a9

Look at Chris' site for a screenshot.
http://www.sellsbrothers.com/tools/#regexd

Jared

"Chris" wrote:
>>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

Lars
Jul 30 '06 #4

P: n/a
Thanks Lars!!!

That worked

Chris
"Lars Graeve" <La********@web.dewrote in message
news:ea*************@news.t-online.com...
Hi

"Chris" <co***********@nospam.yahoo.comschrieb im Newsbeitrag
news:u4**************@TK2MSFTNGP06.phx.gbl...
>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.Multi line

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

"Jared" <Ja***@discussions.microsoft.comwrote in message
news:9C**********************************@microso ft.com...
>>Chris,
Without posting your expression it would be impossible to answer your
question. I would recommend downloading RegEx Designer.Net by Chris
Sells.
It is an excellent tool for testing your expressions.

Attached is the GotDotNet workspace url.
http://www.gotdotnet.com/workspaces/...7-2ed2df2504a9

Look at Chris' site for a screenshot.
http://www.sellsbrothers.com/tools/#regexd

Jared

"Chris" wrote:

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


Lars

Jul 30 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.