Solved

Problem with Regular Expressions and Apostrophes

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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

I have been reconstructing a PHP-based application that has grown into a full blown interface system over the last ten years by a developer that has now gone into business for himself building websites. I am not incredibly fond of writing PHP code o…
Do you hate spam? I do, and I am willing to bet you do as well. I often wonder, though, "if people hate spam so much, why do they still post their email addresses on the web?" I'm not talking about a plain-text posting here. I am referring to the fa…
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…

744 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

14 Experts available now in Live!

Get 1:1 Help Now