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

Regular Expression - Unprintable Character

Hello, I have an file that I am reading and it has some goffy characters in
it and I want to use a regular expression to clean up those characters. I am
not sure how to construct a regular expression which find these characters
and replace them with spaces. I am guessing that a regular expression which
would find the "good" values would look something like this..

Regex expr = new Regex (@"\w()\.,!@#$%<>" - but I am looking for anything
which is the oposite of that, as if I find something which is not in this
list, I want to replace it with spaces. (i.e expr.Replace("MyText|", " ");
)

I was thinking of using the following, but how to I tell it all the other
characters it should exclude from the match? Is there a "NOT" instruction?
Regex regexpr = new Regex (@"\W");

Hopefully this make sense...

Thanks in advance for your assistance!!!
Nov 17 '05 #1
2 2409
Jim Heavey wrote:
Is there a "NOT" instruction?

[abc] matches a or b or c
[^abc] anything but a, b or c

Mit freundlichen Grüßen aus Kiel

Thomas Richter

--
ARIVA.DE AG, Thomas Richter, Diplominformatiker, Entwickler
Ostseekai 2, 24103 Kiel
Tel. (+49) 0431 97108-27, Fax. (+49) 0431 97108-29
E-Mail: tr@ariva.de, Web: www.ariva.de
Nov 17 '05 #2


Jim Heavey wrote:
Hello, I have an file that I am reading and it has some goffy characters in
it and I want to use a regular expression to clean up those characters. I am
not sure how to construct a regular expression which find these characters
and replace them with spaces. I am guessing that a regular expression which
would find the "good" values would look something like this..

Regex expr = new Regex (@"\w()\.,!@#$%<>" - but I am looking for anything
which is the oposite of that, as if I find something which is not in this
list, I want to replace it with spaces. (i.e expr.Replace("MyText|", " ");
)

I was thinking of using the following, but how to I tell it all the other
characters it should exclude from the match? Is there a "NOT" instruction?


Yes!

Just as [abcd] matches a single character which is one of a b c or d,
[^abcd] matches a single character which is NOT one of a b c or d. So
given that

\w()\.,!@#$%<>

are your 'good' characters,

[^\w()\.,!@#$%<>]

will match any 'bad' character.

--
Larry Lard
Replies to group please

Nov 17 '05 #3

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

Similar topics

1
by: Kenneth McDonald | last post by:
I'm working on the 0.8 release of my 'rex' module, and would appreciate feedback, suggestions, and criticism as I work towards finalizing the API and feature sets. rex is a module intended to make...
11
by: Dimitris Georgakopuolos | last post by:
Hello, I have a text file that I load up to a string. The text includes certain expression like {firstName} or {userName} that I want to match and then replace with a new expression. However,...
2
by: Brian Kitt | last post by:
I have a process where I do some minimal reformating on a TAB delimited document to prepare for DTS load. This process has been running fine, but I recently made a change. I have a Full Text...
6
by: Ludwig | last post by:
Hi, i'm using the regular expression \b\w to find the beginning of a word, in my C# application. If the word is 'public', for example, it works. However, if the word is '<public', it does not...
15
by: Mark Rae | last post by:
Hi, I'm trying to construct a RegEx pattern which will validate a string so that it can contain: only the numerical characters from 0 to 9 i.e. no decimal points, negative signs, exponentials...
3
by: Zach | last post by:
Hello, Please forgive if this is not the most appropriate newsgroup for this question. Unfortunately I didn't find a newsgroup specific to regular expressions. I have the following regular...
25
by: Mike | last post by:
I have a regular expression (^(.+)(?=\s*).*\1 ) that results in matches. I would like to get what the actual regular expression is. In other words, when I apply ^(.+)(?=\s*).*\1 to " HEART...
3
by: Zeba | last post by:
Hi guys, I need some help regarding regular expressions. Consider the following statement : System.Text.RegularExpressions.Match match =...
1
by: =?Utf-8?B?Sm9obg==?= | last post by:
How can I use regular expression to detect all the unprintable characters? Please help. Thanks.
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
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...
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
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...
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,...

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.