Home All Groups Group Topic Archive Search About

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

Author
29 Jul 2006 10:26 AM
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

Author
29 Jul 2006 11:42 AM
Jared
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/workspace.aspx?id=01e0dfb7-0182-45cd-94f7-2ed2df2504a9

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

Jared

Show quoteHide quote
"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
>
>
>
Author
29 Jul 2006 12:28 PM
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

Show quoteHide quote
"Jared" <Ja***@discussions.microsoft.com> wrote in message
news:9C7CF7AC-7C0E-46B2-9ECB-5FC54D02DD9A@microsoft.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/workspace.aspx?id=01e0dfb7-0182-45cd-94f7-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
>>
>>
>>
Author
30 Jul 2006 10:29 AM
Lars Graeve
Hi

"Chris" <consult_Chris@nospam.yahoo.com> schrieb im Newsbeitrag
news:u4K2HqwsGHA.4612@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.

Show quoteHide quote
>
> 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
>
> "Jared" <Ja***@discussions.microsoft.com> wrote in message
> news:9C7CF7AC-7C0E-46B2-9ECB-5FC54D02DD9A@microsoft.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/workspace.aspx?id=01e0dfb7-0182-45cd-94f7-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
Author
30 Jul 2006 9:55 PM
Chris
Thanks Lars!!!

That worked

Chris


Show quoteHide quote
"Lars Graeve" <LarsGra***@web.de> wrote in message
news:eai1m4$ges$01$1@news.t-online.com...
> Hi
>
> "Chris" <consult_Chris@nospam.yahoo.com> schrieb im Newsbeitrag
> news:u4K2HqwsGHA.4612@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.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
>>
>> "Jared" <Ja***@discussions.microsoft.com> wrote in message
>> news:9C7CF7AC-7C0E-46B2-9ECB-5FC54D02DD9A@microsoft.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/workspace.aspx?id=01e0dfb7-0182-45cd-94f7-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
>