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. ??? 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. ???
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. ???
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"]
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. ???
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. ???
'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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
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...
|
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...
|
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
...
|
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...
|
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...
|
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 =...
|
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 ...
|
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...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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$) {
}
...
|
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...
|
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
|
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...
|
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: 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,...
|
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...
|
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,...
| |