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

Regex Issues

I have the following System.Text.RegularExpressions.Regex that is supposed
to remove this predefined list of garbage characters from contact names that
come in on import files :

Dim _dropContactGarbage As New Regex( _
"([" & Chr(0) & "-" & Chr(31) & "]+)|" & _
"([" & Chr(33) & "-" & Chr(38) & "]+)|" & _
"([" & Chr(40) & "-" & Chr(44) & "]+)|" & _
"([" & Chr(47) & "-" & Chr(47) & "]+)|" & _
"([" & Chr(58) & "-" & Chr(64) & "]+)|" & _
"([" & Chr(91) & "-" & Chr(96) & "]+)|" & _
"([" & Chr(123) & "-" & Chr(127) & "]+)|" & _
"([" & Chr(152) & "]+)|" & _
"([" & Chr(155) & "-" & Chr(159) & "]+)|" & _
"([" & Chr(166) & "-" & Chr(224) & "]+)|" & _
"([" & Chr(226) & "-" & Chr(255) & "]+)")

We use it like this:

value = _dropContactGarbage.Replace(value, "")

But the Regex constructor is throwing an ArgumentException whose Message
property says only "Parse ([". There is no inner exception. Normally, if I
have a string expression that's wrong, I would Console.WriteLine() it. But
in this case, it doesn't WriteLine correctly, because some of the characters
in the expression are control characters, so what it displays is not
visually correct.

I have slaved over this issue for hours and hours and I can only guess that
one of the items must be escaped with a "\" or something, but I cannot
figure it out. I have already been all over the MSDN help topics for the
Regex Class.

Help?

--
Peace & happy computing,

Mike Labosh, MCSD
"After very careful consideration, I have come
to the conclusion that this new system SUCKS"
-- General Barringer, from WARGAMES
Nov 21 '05 #1
7 2213
I think you're having problems with all those &'s between the brakets.
Maybe?

"([Chr(0) & "-" & Chr(31) ]+)|"
"Mike Labosh" <ml*****@hotmail.com> wrote in message
news:en**************@TK2MSFTNGP10.phx.gbl...
I have the following System.Text.RegularExpressions.Regex that is supposed
to remove this predefined list of garbage characters from contact names
that come in on import files :

Dim _dropContactGarbage As New Regex( _
"([" & Chr(0) & "-" & Chr(31) & "]+)|" & _
"([" & Chr(33) & "-" & Chr(38) & "]+)|" & _
"([" & Chr(40) & "-" & Chr(44) & "]+)|" & _
"([" & Chr(47) & "-" & Chr(47) & "]+)|" & _
"([" & Chr(58) & "-" & Chr(64) & "]+)|" & _
"([" & Chr(91) & "-" & Chr(96) & "]+)|" & _
"([" & Chr(123) & "-" & Chr(127) & "]+)|" & _
"([" & Chr(152) & "]+)|" & _
"([" & Chr(155) & "-" & Chr(159) & "]+)|" & _
"([" & Chr(166) & "-" & Chr(224) & "]+)|" & _
"([" & Chr(226) & "-" & Chr(255) & "]+)")

We use it like this:

value = _dropContactGarbage.Replace(value, "")

But the Regex constructor is throwing an ArgumentException whose Message
property says only "Parse ([". There is no inner exception. Normally, if
I have a string expression that's wrong, I would Console.WriteLine() it.
But in this case, it doesn't WriteLine correctly, because some of the
characters in the expression are control characters, so what it displays
is not visually correct.

I have slaved over this issue for hours and hours and I can only guess
that one of the items must be escaped with a "\" or something, but I
cannot figure it out. I have already been all over the MSDN help topics
for the Regex Class.

Help?

--
Peace & happy computing,

Mike Labosh, MCSD
"After very careful consideration, I have come
to the conclusion that this new system SUCKS"
-- General Barringer, from WARGAMES

Nov 21 '05 #2
>> Dim _dropContactGarbage As New Regex( _
"([" & Chr(0) & "-" & Chr(31) & "]+)|" & _
"([" & Chr(33) & "-" & Chr(38) & "]+)|" & _
"([" & Chr(40) & "-" & Chr(44) & "]+)|" & _
"([" & Chr(47) & "-" & Chr(47) & "]+)|" & _
"([" & Chr(58) & "-" & Chr(64) & "]+)|" & _
"([" & Chr(91) & "-" & Chr(96) & "]+)|" & _
"([" & Chr(123) & "-" & Chr(127) & "]+)|" & _
"([" & Chr(152) & "]+)|" & _
"([" & Chr(155) & "-" & Chr(159) & "]+)|" & _
"([" & Chr(166) & "-" & Chr(224) & "]+)|" & _
"([" & Chr(226) & "-" & Chr(255) & "]+)")
I think you're having problems with all those &'s between the brakets.
Maybe?

"([Chr(0) & "-" & Chr(31) ]+)|"


No. It's not the concatenation. The dumb thing *used to work*, but they
want me to change a couple of the character ranges. So all I have done is
changed a couple of the character codes passed to the Chr() function. Now
it's b0rken.

What I am currently attempting is to create a Regex from each single line of
my OP so I can find which one is causing the issue, then perhaps I can
determine a workaround.
--
Peace & happy computing,

Mike Labosh, MCSD
"Musha ring dum a doo dum a da!" -- James Hetfield
Nov 21 '05 #3
jg
make sure the new character code does not special meaning in regex. IF they
do, use the escape prefix before the " & chr...

Sorry, I don't know the details, but I am sure you can look it up in msdn
under regex

"Mike Labosh" <ml*****@hotmail.com> wrote in message
news:e3**************@TK2MSFTNGP15.phx.gbl...
Dim _dropContactGarbage As New Regex( _
"([" & Chr(0) & "-" & Chr(31) & "]+)|" & _
"([" & Chr(33) & "-" & Chr(38) & "]+)|" & _
"([" & Chr(40) & "-" & Chr(44) & "]+)|" & _
"([" & Chr(47) & "-" & Chr(47) & "]+)|" & _
"([" & Chr(58) & "-" & Chr(64) & "]+)|" & _
"([" & Chr(91) & "-" & Chr(96) & "]+)|" & _
"([" & Chr(123) & "-" & Chr(127) & "]+)|" & _
"([" & Chr(152) & "]+)|" & _
"([" & Chr(155) & "-" & Chr(159) & "]+)|" & _
"([" & Chr(166) & "-" & Chr(224) & "]+)|" & _
"([" & Chr(226) & "-" & Chr(255) & "]+)")

I think you're having problems with all those &'s between the brakets.
Maybe?

"([Chr(0) & "-" & Chr(31) ]+)|"


No. It's not the concatenation. The dumb thing *used to work*, but they
want me to change a couple of the character ranges. So all I have done is
changed a couple of the character codes passed to the Chr() function. Now
it's b0rken.

What I am currently attempting is to create a Regex from each single line
of my OP so I can find which one is causing the issue, then perhaps I can
determine a workaround.
--
Peace & happy computing,

Mike Labosh, MCSD
"Musha ring dum a doo dum a da!" -- James Hetfield

Nov 21 '05 #4
> make sure the new character code does not special meaning in regex. IF
they do, use the escape prefix before the " & chr...
That's what I'm trying to do. Each line of the expression seems to work by
itself. So I am now trying varying combinations.
Sorry, I don't know the details, but I am sure you can look it up in msdn
under regex


heh. If you saw all the MSDN printouts on my desk, you would hurt me for
killing trees :)

--
Peace & happy computing,

Mike Labosh, MCSD
"Musha ring dum a doo dum a da!" -- James Hetfield
Nov 21 '05 #5
It barks at me until I remove this line:
"([" & Chr(155) & "-" & Chr(159) & "]+)|" & _

I'm not sure why.

"Mike Labosh" <ml*****@hotmail.com> wrote in message
news:en**************@TK2MSFTNGP10.phx.gbl...
I have the following System.Text.RegularExpressions.Regex that is supposed
to remove this predefined list of garbage characters from contact names
that come in on import files :

Dim _dropContactGarbage As New Regex( _
"([" & Chr(0) & "-" & Chr(31) & "]+)|" & _
"([" & Chr(33) & "-" & Chr(38) & "]+)|" & _
"([" & Chr(40) & "-" & Chr(44) & "]+)|" & _
"([" & Chr(47) & "-" & Chr(47) & "]+)|" & _
"([" & Chr(58) & "-" & Chr(64) & "]+)|" & _
"([" & Chr(91) & "-" & Chr(96) & "]+)|" & _
"([" & Chr(123) & "-" & Chr(127) & "]+)|" & _
"([" & Chr(152) & "]+)|" & _
"([" & Chr(155) & "-" & Chr(159) & "]+)|" & _
"([" & Chr(166) & "-" & Chr(224) & "]+)|" & _
"([" & Chr(226) & "-" & Chr(255) & "]+)")

We use it like this:

value = _dropContactGarbage.Replace(value, "")

But the Regex constructor is throwing an ArgumentException whose Message
property says only "Parse ([". There is no inner exception. Normally, if
I have a string expression that's wrong, I would Console.WriteLine() it.
But in this case, it doesn't WriteLine correctly, because some of the
characters in the expression are control characters, so what it displays
is not visually correct.

I have slaved over this issue for hours and hours and I can only guess
that one of the items must be escaped with a "\" or something, but I
cannot figure it out. I have already been all over the MSDN help topics
for the Regex Class.

Help?

--
Peace & happy computing,

Mike Labosh, MCSD
"After very careful consideration, I have come
to the conclusion that this new system SUCKS"
-- General Barringer, from WARGAMES

Nov 21 '05 #6
parsing "([>-Y]+)|" - [x-y] range in reverse order.

"Chris Burgess" <cb******@converse.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
It barks at me until I remove this line:
"([" & Chr(155) & "-" & Chr(159) & "]+)|" & _

I'm not sure why.

"Mike Labosh" <ml*****@hotmail.com> wrote in message
news:en**************@TK2MSFTNGP10.phx.gbl...
I have the following System.Text.RegularExpressions.Regex that is supposed
to remove this predefined list of garbage characters from contact names
that come in on import files :

Dim _dropContactGarbage As New Regex( _
"([" & Chr(0) & "-" & Chr(31) & "]+)|" & _
"([" & Chr(33) & "-" & Chr(38) & "]+)|" & _
"([" & Chr(40) & "-" & Chr(44) & "]+)|" & _
"([" & Chr(47) & "-" & Chr(47) & "]+)|" & _
"([" & Chr(58) & "-" & Chr(64) & "]+)|" & _
"([" & Chr(91) & "-" & Chr(96) & "]+)|" & _
"([" & Chr(123) & "-" & Chr(127) & "]+)|" & _
"([" & Chr(152) & "]+)|" & _
"([" & Chr(155) & "-" & Chr(159) & "]+)|" & _
"([" & Chr(166) & "-" & Chr(224) & "]+)|" & _
"([" & Chr(226) & "-" & Chr(255) & "]+)")

We use it like this:

value = _dropContactGarbage.Replace(value, "")

But the Regex constructor is throwing an ArgumentException whose Message
property says only "Parse ([". There is no inner exception. Normally,
if I have a string expression that's wrong, I would Console.WriteLine()
it. But in this case, it doesn't WriteLine correctly, because some of the
characters in the expression are control characters, so what it displays
is not visually correct.

I have slaved over this issue for hours and hours and I can only guess
that one of the items must be escaped with a "\" or something, but I
cannot figure it out. I have already been all over the MSDN help topics
for the Regex Class.

Help?

--
Peace & happy computing,

Mike Labosh, MCSD
"After very careful consideration, I have come
to the conclusion that this new system SUCKS"
-- General Barringer, from WARGAMES


Nov 21 '05 #7
Mike,
Rather then literally using Chr(0), Chr(31), Chr(33), ..., I would recommend
the RegEx Character Escape sequences.

http://msdn.microsoft.com/library/de...terescapes.asp

Something like:

' With ASCII character escapes
Dim _dropContactGarbage As New Regex( _
"([\x00-\x1F]+)|" & _
"([\x21-\x26]+)|" & _
"([\x28-\x2C]+)|" & _
...

Of course you may have problems with Chr(128) & above, as Chr(128) is an
ANSI char code, while Regex expects ASCII and/or Unicode. As you know ASCII
is 7 bit (0 to 127) & Unicode in RegEx needs 4 digits (\u0000).

' with Unicode character escapes
Dim _dropContactGarbage As New Regex( _
"([\u0000-\u001F]+)|" & _
"([\u0021-\u0026]+)|" & _
"([\u0028-\u002C]+)|" & _
It might be "easier" if you used a the predefined character classes (\s \w
\W \s ...) instead:

http://msdn.microsoft.com/library/de...terclasses.asp

Something like:
Dim _dropContactGarbage As New Regex("\W")

Which says match any nonword character...

Expresso & RegEx Workbench both have wizards of varying degrees to help you
build your expression, plus they allow you to test your expressions, also
the analyzer/interpreter in each is rather handy.

Expresso:
http://www.ultrapico.com/Expresso.htm

RegEx Workbench:
http://www.gotdotnet.com/Community/U...-4ee2729d7322A

tutorial & reference on using regular expressions:
http://www.regular-expressions.info/

The MSDN's documentation on regular expressions:
http://msdn.microsoft.com/library/de...geElements.asp

Hope this helps
Jay

"Mike Labosh" <ml*****@hotmail.com> wrote in message
news:en**************@TK2MSFTNGP10.phx.gbl...
|I have the following System.Text.RegularExpressions.Regex that is supposed
| to remove this predefined list of garbage characters from contact names
that
| come in on import files :
|
| Dim _dropContactGarbage As New Regex( _
| "([" & Chr(0) & "-" & Chr(31) & "]+)|" & _
| "([" & Chr(33) & "-" & Chr(38) & "]+)|" & _
| "([" & Chr(40) & "-" & Chr(44) & "]+)|" & _
| "([" & Chr(47) & "-" & Chr(47) & "]+)|" & _
| "([" & Chr(58) & "-" & Chr(64) & "]+)|" & _
| "([" & Chr(91) & "-" & Chr(96) & "]+)|" & _
| "([" & Chr(123) & "-" & Chr(127) & "]+)|" & _
| "([" & Chr(152) & "]+)|" & _
| "([" & Chr(155) & "-" & Chr(159) & "]+)|" & _
| "([" & Chr(166) & "-" & Chr(224) & "]+)|" & _
| "([" & Chr(226) & "-" & Chr(255) & "]+)")
|
| We use it like this:
|
| value = _dropContactGarbage.Replace(value, "")
|
| But the Regex constructor is throwing an ArgumentException whose Message
| property says only "Parse ([". There is no inner exception. Normally, if
I
| have a string expression that's wrong, I would Console.WriteLine() it.
But
| in this case, it doesn't WriteLine correctly, because some of the
characters
| in the expression are control characters, so what it displays is not
| visually correct.
|
| I have slaved over this issue for hours and hours and I can only guess
that
| one of the items must be escaped with a "\" or something, but I cannot
| figure it out. I have already been all over the MSDN help topics for the
| Regex Class.
|
| Help?
|
| --
| Peace & happy computing,
|
| Mike Labosh, MCSD
| "After very careful consideration, I have come
| to the conclusion that this new system SUCKS"
| -- General Barringer, from WARGAMES
|
|
Nov 21 '05 #8

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

Similar topics

75
by: Xah Lee | last post by:
http://python.org/doc/2.4.1/lib/module-re.html http://python.org/doc/2.4.1/lib/node114.html --------- QUOTE The module defines several functions, constants, and an exception. Some of the...
2
by: Ram Sundaram | last post by:
Hi, I am trying to port some linux code to windows under Visual studio. The regex package currently used is the GNU regex package which calls for <strings.h>. This is not found in visual studio....
3
by: Chris | last post by:
I need to write a function that will remove a specified parameter from a URL. For example: removeParam("param1", "http://mysite.com/mypage.htm?param1=1&param2=2"); would return: ...
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 ...
4
by: Brian Henry | last post by:
I have phone numbers like this in a data table 123-435-1234 1231231234 432.234.2321 they all have different formatting, what I want to do is get them all formatted like this (123) 123-1234
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...
16
by: Mark Chambers | last post by:
Hi there, I'm seeking opinions on the use of regular expression searching. Is there general consensus on whether it's now a best practice to rely on this rather than rolling your own (string)...
15
by: nagar | last post by:
I need to split a string whenever a separator string is present (lets sey #Key(val) where val is a variable) and rejoin it in the proper order after doing some processing. Is there a way to use...
4
by: CJ | last post by:
Is this the format to parse a string and return the value between the item? Regex pRE = new Regex("<File_Name>.*>(?<insideText>.*)</File_Name>"); I am trying to parse this string. ...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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...
0
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,...
0
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...

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.