Regular Expression : Grab everything to right of comma

I want to use regular expressions in to grab everything to the right of the last comma. I realized using string functions is a way to do this but I want to use regular expressions.

The number of characters will be varying and in some cases there may be a decimal point and cents left over.

Ex.
"M111        ,11/1/2005 0:00:00,13455.55";

Ans. 13455.55

How can I do this?
marcon33Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

dunglaCommented:
Hi marcon33,

Try this one
string pattern = @"\b(,)\b[0-9]?.+";
string content = "M111        ,11/1/2005 0:00:00,13455.55";
Match m = Regex.Match(content, pattern, RegexOptions.IgnoreCase);
if (m.Success)
      Console.WriteLine(m.Value.Replace(",", string.Empty));

// result:
13455.55
0
Fernando SotoRetiredCommented:
Hi marcon33;

For strings formated the way the example was given this will work.

using System.Text.RegularExpressions;

      string input = "M111        ,11/1/2005 0:00:00,13455.55";
      string LastValue = String.Empty;
      Match m = Regex.Match(input, @":\d\d\s*?,\s*?(\d+\.?\d*)");
      LastValue = m.Groups[1].Value;
      MessageBox.Show("Last value is = " + LastValue);


Fernando
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Fernando SotoRetiredCommented:
Hi dungla;

You could modify your pattern so that you do not have to do a replace on the string returned from Regex. You can change the pattern to "\b,\b([0-9]?.+)" and then to get the results of the match you can do it like this.

     m.Groups[1].Value;

The other thing about the pattern you are using is that it matches only the first digit and excepts any character after it. You can change your pattern to this "\b,\b([0-9]+\.?[0-9]*)" only to except digits and a decimal point.

Fernando
0
dunglaCommented:
Thanks Fernando
0
rbvoigtCommented:
In perl I would use
/([^,]*)$/

I think the .NET regex syntax is very close... you want to anchor to the end of the string "$", then include all characters except comma "[^,]", as many times as possible "*".
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.