Solved

Problem with Regular Expressions and Apostrophes

Posted on 2007-04-06
4
400 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

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…
We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
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…

911 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now