473,837 Members | 1,535 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2650
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.Reg ularExpressions .RegexOptions =
System.Text.Reg ularExpressions .RegexOptions.M ultiline

Dim oSSNRegex As New Regex(RegExType s.ssnRegex, RegExTypes.opti ons)

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.6vbCrLfCopyri ght
(C) Microsoft Corporation 1996-2001. All rights reserved.vbCrLf vbCrLfUsing
Path: \\WKS3A\c$\Docu ments and Settings\Diana. CFLLAW\Applicat ion
Data\Express\Se ndvbCrLfResults for: WKS3A - Diana.CFLLAWvbC rLfvbCrLfThe MEAN
dictation file size: 0 MBvbCrLfvbCrLfL argest File: 0 MBvbCrLf1 files
considered in
average.vbCrLfv bCrLf========== =============== =============== ====vbCrLfvbCrL fvbCrLfUsing
Path: \\WKS5A\c$\Docu ments and Settings\Diana. CFLLAW\Applicat ion
Data\Express\Se ndvbCrLfResults for: WKS5A - Diana.CFLLAWvbC rLfvbCrLfThe MEAN
dictation file size: 0 MBvbCrLfvbCrLfL argest File: 0 MBvbCrLf1 files
considered in
average.vbCrLfv bCrLf========== =============== =============== ====vbCrLfvbCrL f134
73 9834vbCrLfvbCrL fvbCrLf"

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

Thanks,

Chris

"Jared" <Ja***@discussi ons.microsoft.c omwrote in message
news:9C******** *************** ***********@mic rosoft.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.co mschrieb im Newsbeitrag
news:u4******** ******@TK2MSFTN GP06.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.Reg ularExpressions .RegexOptions =
System.Text.Reg ularExpressions .RegexOptions.M ultiline

Dim oSSNRegex As New Regex(RegExType s.ssnRegex, RegExTypes.opti ons)

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.6vbCrLfCopyri ght (C) Microsoft Corporation 1996-2001. All rights
reserved.vbCrLf vbCrLfUsing Path: \\WKS3A\c$\Docu ments and
Settings\Diana. CFLLAW\Applicat ion Data\Express\Se ndvbCrLfResults for:
WKS3A - Diana.CFLLAWvbC rLfvbCrLfThe MEAN dictation file size: 0
MBvbCrLfvbCrLfL argest File: 0 MBvbCrLf1 files considered in
average.vbCrLfv bCrLf========== =============== =============== ====vbCrLfvbCrL fvbCrLfUsing
Path: \\WKS5A\c$\Docu ments and Settings\Diana. CFLLAW\Applicat ion
Data\Express\Se ndvbCrLfResults for: WKS5A - Diana.CFLLAWvbC rLfvbCrLfThe
MEAN dictation file size: 0 MBvbCrLfvbCrLfL argest File: 0 MBvbCrLf1 files
considered in
average.vbCrLfv bCrLf========== =============== =============== ====vbCrLfvbCrL f134
73 9834vbCrLfvbCrL fvbCrLf"

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

Thanks,

Chris

"Jared" <Ja***@discussi ons.microsoft.c omwrote in message
news:9C******** *************** ***********@mic rosoft.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.co mschrieb im Newsbeitrag
news:u4******** ******@TK2MSFTN GP06.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.Reg ularExpressions .RegexOptions =
System.Text.Re gularExpression s.RegexOptions. Multiline

Dim oSSNRegex As New Regex(RegExType s.ssnRegex, RegExTypes.opti ons)

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.6vbCrLfCopyr ight (C) Microsoft Corporation 1996-2001. All rights
reserved.vbCrL fvbCrLfUsing Path: \\WKS3A\c$\Docu ments and
Settings\Diana .CFLLAW\Applica tion Data\Express\Se ndvbCrLfResults for:
WKS3A - Diana.CFLLAWvbC rLfvbCrLfThe MEAN dictation file size: 0
MBvbCrLfvbCrLf Largest File: 0 MBvbCrLf1 files considered in
average.vbCrLf vbCrLf========= =============== =============== =====vbCrLfvbCr LfvbCrLfUsing
Path: \\WKS5A\c$\Docu ments and Settings\Diana. CFLLAW\Applicat ion
Data\Express\S endvbCrLfResult s for: WKS5A - Diana.CFLLAWvbC rLfvbCrLfThe
MEAN dictation file size: 0 MBvbCrLfvbCrLfL argest File: 0 MBvbCrLf1 files
considered in
average.vbCrLf vbCrLf========= =============== =============== =====vbCrLfvbCr Lf134
73 9834vbCrLfvbCrL fvbCrLf"

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

Thanks,

Chris

"Jared" <Ja***@discussi ons.microsoft.c omwrote in message
news:9C******* *************** ************@mi crosoft.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
2421
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. zzz (empty) 4. www g=h,i=j,l=m
3
5328
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 of what I have tried... string testString = "lkf slkdjflksd sdfjlksdjff fsdjlsdfj flk;sjkf"; while(true) { Regex .Match(testString,@"(\w)"); } ---------------------------------------------------------------------- string testString = "lkf...
1
3393
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 remove from the message once processed. I have to do this as a string and not using any CDO libraries. My problem is that there's normally a large pdf in the file so when I read the file in it's massive and I don't knwo if the XML is at the...
7
1918
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 starting and ending with a *. I tried things like string regex = @"(^*\|*^)"); but it still doesn't work completely (matches on "*test" too for example). If anything could help me with this, that would be appreciated.
8
2597
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: @"@?""""|@?"".*?(?!\\).""|''|'.*?(?!\\).'" I am inputting the entire source file string and using it with RegexOptions.Singleline. This works OK with, unless the string ends with a back-slash. For example: "This is a test\\". Can anybody see how to fix this...
3
5275
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 "<stdin>", line 1, in ? File "/usr/lib/python2.3/sre.py", line 179, in compile return _compile(pattern, flags) File "/usr/lib/python2.3/sre.py", line 230, in _compile
4
1930
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: cond(c,a,b)
3
1939
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. In terms of code, what's the easiest way to make that happen? The code below works fine for identifying the matches, but it doesn't try to extract the surrounding context or display it: currPageText = numberOfMatches =...
3
1318
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 string", re.findall(r"* (\w+)","test a string") will work, but what if there is not "a" but "an"(test a string)? the will failed because it will stop at the first character "a". I guess people not always use this kind of way to filter words?...
0
9844
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10578
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10276
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9409
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7813
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7006
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5670
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5851
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4477
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.