473,378 Members | 1,333 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

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

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
4 2609
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Alan Pretre | last post by:
Can anyone help me figure out a regex pattern for the following input example: xxx:a=b,c=d,yyy:e=f,zzz:www:g=h,i=j,l=m I would want four matches from this: 1. xxx a=b,c=d 2. yyy e=f 3....
3
by: Jeff McPhail | last post by:
I am using Regex.Match in a large application and the memory is growing out of control. I have tried several ways to try and release the memory and none of them work. Here are some similar examples...
1
by: Mark | last post by:
Hi, I've seen some postings on this but not exactly relating to this posting. I'm reading in a large mail message as a string. In the string is an xml attachment that I need to parse out and...
7
by: Razzie | last post by:
Hey all, Decided to give a shot at Regular expressions - need a bit of help :) I can't seem to find the right regex for matching words like "*test*" or *somevalue*" - in short, all words...
8
by: Bob | last post by:
I need to create a Regex to extract all strings (including quotations) from a C# or C++ source file. After being unsuccessful myself, I found this sample on the internet: ...
3
by: gisleyt | last post by:
I'm trying to compile a perfectly valid regex, but get the error message: r = re.compile(r'(*)(\d{1,3}\.\d{0,2})?(\d*)(\,\d{1,3}\.\d{0,2})?(\d*)?.*') Traceback (most recent call last): File...
4
by: MooMaster | last post by:
I'm trying to develop a little script that does some string manipulation. I have some few hundred strings that currently look like this: cond(a,b,c) and I want them to look like this: ...
3
by: | last post by:
I'm analyzing large strings and finding matches using the Regex class. I want to find the context those matches are found in and to display excerpts of that context, just as a search engine might....
3
by: tecspring | last post by:
I always have no idea about how to express "conclude the entire word" with regexp, while using python, I encountered this problem again... for example, if I want to match the "string" in "test a...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.