Link to home
Start Free TrialLog in
Avatar of ironwill96
ironwill96

asked on

Problem with Regular Expressions and Apostrophes

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
ASKER CERTIFIED SOLUTION
Avatar of ozo
ozo
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ironwill96
ironwill96

ASKER

Will that give me the trailing apostrophe?  i want that apostrophe in there..?
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
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