Solved

Problem with Regular Expressions and Apostrophes

Posted on 2007-04-06
4
414 Views
Last Modified: 2010-04-15
I am having a quirky issue with some regular expressions I am using in a program that is parsing some text.

This is the regular expression I have:  \d*\W\d*\W

and it matches things like:  950.56'  

I've tested this and it returns the way I want when I throw the results into a list box so I get like: 950.56'

However, when I grab the results like this: results = Regex.Matches(resultsTemp[0].Value, strRegularExpression, RegexOptions.IgnoreCase | RegexOptions.Singleline);

Where resultsTemp is another matchcollection, it throws it into those results such that it is now "950.56 "   (without the quotes but with the new trailing space).

Any ideas why it is doing this?


Thanks,
Nathan
0
Comment
Question by:ironwill96
  • 3
4 Comments
 
LVL 84

Accepted Solution

by:
ozo earned 500 total points
ID: 18868387
\W can match "." or " "
dot you want
\d*\W\d*
0
 
LVL 2

Author Comment

by:ironwill96
ID: 18868504
Will that give me the trailing apostrophe?  i want that apostrophe in there..?
0
 
LVL 2

Author Comment

by:ironwill96
ID: 18868662
Tried what you describe using that expression and it still doesn't work.  All that does is remove the apostrophe from the end which is not what I wanted.  I want it to show up in my results MatchCollection but its not.  When I dump it into a list box the apostrophe shows up, but for some reason either when it gets converted into the MatchCollection or when it is pulled out into a string it loses the trailing apostrophe and replaces it with a space!

Nathan
0
 
LVL 2

Author Comment

by:ironwill96
ID: 18868673
Figured out my issue, actually wasn't the Reg Expression but was the StreamReader I was using to load the text from a text file!  It was set to UTF8 instead of "Default" encoding so it was stripping off the apostrophes and other symbols I needed!

Thanks for your help,

Nathan
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Hey!! 5 37
C# Gridview 1 49
How to verify that an email address ends with a particular set of characters in C#? 2 27
Unlocking a column in excel using C# 17 21
Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

820 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question