Solved

Problem with Regular Expressions and Apostrophes

Posted on 2007-04-06
4
420 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
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…

739 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