473,386 Members | 1,803 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,386 software developers and data experts.

RegEx Not Working In .NET

Perhaps someone here can help me out...

RegEx: "^.*\d{5}(-\d{4})?.*$"
Intended Purpose: To strip out the City/State/ZipCode line from a signature.
Sample Text:

Joe Jackson
131 W. 5th Street
New York, NY 10023

RegEx Should Return: "New York, NY 10023"

1) This RegEx works correctly in Excel using "Microsoft VBScript Regular
Expressions 5.5" object library
2) This RegEx works correctly with web-based .NET processor on
http://www.regexlib.com/RETester.aspx
3) This RegEx DOES NOT WORK in .NET v1.1 (well, at least not for me!)
4) I found the article "FIX: The Regex class and the Match class may not
correctly find matches for a regular expression" on Microsoft Support site
(http://support.microsoft.com/default...;en-us;822923), however the
versions of the files that they say create the fix are OLDER than the ones I
have, so perhaps this is a fix for .NET v1.0. ???
Nov 16 '05 #1
6 2504

One way to solve this is to set the multiline option,
RegexOptions.Multiline.

Dim regexCityLine As New Regex( _
"^.*\d{5}(-\d{4})?.*$", _
RegexOptions.Multiline)

Robby
VB.Net
"BigAl" <Bi***@discussions.microsoft.com> wrote in message
news:EE**********************************@microsof t.com...
Perhaps someone here can help me out...

RegEx: "^.*\d{5}(-\d{4})?.*$"
Intended Purpose: To strip out the City/State/ZipCode line from a
signature.
Sample Text:

Joe Jackson
131 W. 5th Street
New York, NY 10023

RegEx Should Return: "New York, NY 10023"

1) This RegEx works correctly in Excel using "Microsoft VBScript Regular
Expressions 5.5" object library
2) This RegEx works correctly with web-based .NET processor on
http://www.regexlib.com/RETester.aspx
3) This RegEx DOES NOT WORK in .NET v1.1 (well, at least not for me!)
4) I found the article "FIX: The Regex class and the Match class may not
correctly find matches for a regular expression" on Microsoft Support site
(http://support.microsoft.com/default...;en-us;822923), however
the
versions of the files that they say create the fix are OLDER than the ones
I
have, so perhaps this is a fix for .NET v1.0. ???

Nov 16 '05 #2
I've tried both SingleLine and MultiLine options, and neither seem to work.

"Robby" wrote:

One way to solve this is to set the multiline option,
RegexOptions.Multiline.

Dim regexCityLine As New Regex( _
"^.*\d{5}(-\d{4})?.*$", _
RegexOptions.Multiline)

Robby
VB.Net
"BigAl" <Bi***@discussions.microsoft.com> wrote in message
news:EE**********************************@microsof t.com...
Perhaps someone here can help me out...

RegEx: "^.*\d{5}(-\d{4})?.*$"
Intended Purpose: To strip out the City/State/ZipCode line from a
signature.
Sample Text:

Joe Jackson
131 W. 5th Street
New York, NY 10023

RegEx Should Return: "New York, NY 10023"

1) This RegEx works correctly in Excel using "Microsoft VBScript Regular
Expressions 5.5" object library
2) This RegEx works correctly with web-based .NET processor on
http://www.regexlib.com/RETester.aspx
3) This RegEx DOES NOT WORK in .NET v1.1 (well, at least not for me!)
4) I found the article "FIX: The Regex class and the Match class may not
correctly find matches for a regular expression" on Microsoft Support site
(http://support.microsoft.com/default...;en-us;822923), however
the
versions of the files that they say create the fix are OLDER than the ones
I
have, so perhaps this is a fix for .NET v1.0. ???


Nov 16 '05 #3
BigAl wrote:
Perhaps someone here can help me out...

RegEx: "^.*\d{5}(-\d{4})?.*$"
Intended Purpose: To strip out the City/State/ZipCode line from a signature.
Sample Text:

Joe Jackson
131 W. 5th Street
New York, NY 10023

RegEx Should Return: "New York, NY 10023"


You should post what code you were using.
Assuming you were passing all 3 lines (instead of splitting them up and
passing the last line only), you can try the regex the code below. The
code is in the language boo: http://boo.codehaus.org/

s = """
Joe Jackson
131 W. 5th Street
New York, NY 10023
"""

r =
/(?<=\n)\s*(?<city>[^\n]+)\s*,\s*(?<state>\w+)\s+(?<zip>\d{5}(-\d{4})?).*$/.Match(s)

print r.Groups["city"]
print r.Groups["state"]
print r.Groups["zip"]
Nov 16 '05 #4

It works for me in VB.Net and C# uses the same Regex object. Can you post
the code you are using so I can see why it is not working for you?

Robby

"BigAl" <Bi***@discussions.microsoft.com> wrote in message
news:77**********************************@microsof t.com...
I've tried both SingleLine and MultiLine options, and neither seem to
work.

"Robby" wrote:

One way to solve this is to set the multiline option,
RegexOptions.Multiline.

Dim regexCityLine As New Regex( _
"^.*\d{5}(-\d{4})?.*$", _
RegexOptions.Multiline)

Robby
VB.Net
"BigAl" <Bi***@discussions.microsoft.com> wrote in message
news:EE**********************************@microsof t.com...
> Perhaps someone here can help me out...
>
> RegEx: "^.*\d{5}(-\d{4})?.*$"
> Intended Purpose: To strip out the City/State/ZipCode line from a
> signature.
> Sample Text:
>
> Joe Jackson
> 131 W. 5th Street
> New York, NY 10023
>
> RegEx Should Return: "New York, NY 10023"
>
> 1) This RegEx works correctly in Excel using "Microsoft VBScript
> Regular
> Expressions 5.5" object library
> 2) This RegEx works correctly with web-based .NET processor on
> http://www.regexlib.com/RETester.aspx
> 3) This RegEx DOES NOT WORK in .NET v1.1 (well, at least not for me!)
> 4) I found the article "FIX: The Regex class and the Match class may
> not
> correctly find matches for a regular expression" on Microsoft Support
> site
> (http://support.microsoft.com/default...;en-us;822923),
> however
> the
> versions of the files that they say create the fix are OLDER than the
> ones
> I
> have, so perhaps this is a fix for .NET v1.0. ???


Nov 16 '05 #5
BigAl,

Your Regex works fine for me in Expresso using Framework 1.1. Perhaps there
is a problem in your code. You should set Multiline ON and Singleline OFF.

Here is the C# Regex definition as generated by Expresso:

public static Regex regex = new Regex(
@"^.*\d{5}(-\d{4})?.*$",
RegexOptions.Multiline
| RegexOptions.Compiled
);

Expresso can be used to debug your regular expression, is free, and can be
found at http://www.ultrapico.com

Regards,

Jim

"BigAl" <Bi***@discussions.microsoft.com> wrote in message
news:EE**********************************@microsof t.com...
Perhaps someone here can help me out...

RegEx: "^.*\d{5}(-\d{4})?.*$"
Intended Purpose: To strip out the City/State/ZipCode line from a
signature.
Sample Text:

Joe Jackson
131 W. 5th Street
New York, NY 10023

RegEx Should Return: "New York, NY 10023"

1) This RegEx works correctly in Excel using "Microsoft VBScript Regular
Expressions 5.5" object library
2) This RegEx works correctly with web-based .NET processor on
http://www.regexlib.com/RETester.aspx
3) This RegEx DOES NOT WORK in .NET v1.1 (well, at least not for me!)
4) I found the article "FIX: The Regex class and the Match class may not
correctly find matches for a regular expression" on Microsoft Support site
(http://support.microsoft.com/default...;en-us;822923), however
the
versions of the files that they say create the fix are OLDER than the ones
I
have, so perhaps this is a fix for .NET v1.0. ???

Nov 16 '05 #6
'I've tried to extract the basics of what I'm doing below...
----------------------------------------------------------
Sub Test
Dim sText as String, sCity as String, sState as String, sZip as String
sText = "Joe Jackson" & vbCrLf & "123 Main St." & vbCrLf & "New York, NY
10023"
GetCityStateZip sText, sCity, sState, sZip
Debug.Pring sCity &","& sState & ","& sZip
End Sub

Private Sub GetCityStateZip(ByRef sText As String, ByRef sCity As String,
ByRef sState As String, ByRef sZip As String)
Const REG_EXP_ZIPCODE = "\d{5}(-\d{4})?$"
Const REG_EXP_CITY_STATE_ZIP = "^.*\d{5}(-\d{4})?.*$"

Dim sCityStateZip As String, sCityState As String

sCityStateZip = RetrieveRegExp(REG_EXP_CITY_STATE_ZIP, sText)
'Find city/state/zip
If sCityStateZip = "" Then Exit Sub

sZip = RetrieveRegExp(REG_EXP_ZIPCODE, sCityStateZip)
'Find Zip

sCity = Pop(",", sCityState) 'Parse City
sState = Trim(sCityState) 'Get State

End Sub

Function RetrieveRegExp(ByVal patrn, ByVal strng)
Dim RetStr As String
Dim iRegExOptions As Integer = ExplicitCapture + IgnoreCase +
Multiline
Dim regEx As New regEx(patrn), Match As Match, Matches As
MatchCollection ' Create variable.

Matches = regEx.Matches(strng) ' Execute search.
For Each Match In Matches ' Iterate Matches collection.
RetStr = Match.Value
Next
RetrieveRegExp = RetStr

End Function

Nov 16 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: Peter Kleiweg | last post by:
I want to use regular expressions with less typing. Like this: A / 'b.(..)' # test for regex 'b...' in A A # get the last whole match A # get the first group in the...
16
by: Andrew Baker | last post by:
I am trying to write a function which provides my users with a file filter. The filter used to work just using the VB "Like" comparision, but I can't find the equivilant in C#. I looked at...
6
by: Dave | last post by:
I'm struggling with something that should be fairly simple. I just don't know the regext syntax very well, unfortunately. I'd like to parse words out of what is basically a boolean search...
17
by: clintonG | last post by:
I'm using an .aspx tool I found at but as nice as the interface is I think I need to consider using others. Some can generate C# I understand. Your preferences please... <%= Clinton Gallagher ...
11
by: shapper | last post by:
Hello, I need to create a REGEX which accepts only phone numbers. The phone numbers start allways with 261, 21, 96 or 91 and have 7 numbers after it. Something like. 261 1223346, 21...
4
by: Henrik Dahl | last post by:
Hello! In my application I have a need for using a regular expression now and then. Often the same regular expression must be used multiple times. For performance reasons I use the...
1
by: al.moorthi | last post by:
the below program is working in Suse and not working on Cent 5: can any body have the solution ? #include <regex.h> #include <stdlib.h> #include <stdio.h> int main(){ char cool =...
1
by: mad.scientist.jr | last post by:
I am working in C# ASP.NET framework 1.1 and for some reason Regex.Split isn't working as expected. When trying to split a string, Split is returning an array with the entire string in element ...
9
by: kummu4help | last post by:
can anyone give me a regex to validate the password with following conditions hope i am clear. i tried with ctype_alnum() function in php but it is accepting if all characters or either...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...
0
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.