Regular Expression needed

I have a string that is always 9 characters long. I want to remove any 0 that occurs in the middle of the string but NOT remove trailing zero's. 3 examples below.

Original string        desired result
690091500           6991500
690001500           691500
690454600           69454600
691456999           691456999

Can someone help?
boukakaAsked:
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.

ozoCommented:
0+(?=\d)
0
boukakaAuthor Commented:
Please excuse my ignorance .

If I have string Policy = line.Substring(25,9).. how do I incorporate that regular expression to make it work for me?
0
nedfineCommented:
if you want to know how to use regex in C# take a look at this :

http://www.c-sharpcorner.com/UploadFile/prasad_1/RegExpPSD12062005021717AM/RegExpPSD.aspx 


Thanks
Ned
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
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

boukakaAuthor Commented:
Thank you, that site is very helpful, I'd like to give you the points because this will solve a lot of my Regex issues going forward. We ended up going a different route with my particular problem. We ended up doing the following which works like a charm.


                        string str;
                        str = "";
                        bool doNothing = false;
                        int nonZero = -1;
                        int firstZero = -1;
                        if(line.Substring(25,9).IndexOf("0") == -1)
                        {
                            doNothing = true;
                        }
                        else
                        {
                            for(int i = 25; i < 35; i++)
                            {
                                if(line.Substring(i,1) == "0")
                                {
                                    firstZero = i;
                                    break;
                                }
                            }
 
                            for(int i = firstZero; i < 35; i++)
                            {
                                if(line.Substring(i,1) != "0")
                                {
                                    nonZero = i;
                                    break;
                                }
                            }
                            if(nonZero == -1)
                            {
                                doNothing = true;
                            }
                        }
                        if(doNothing)
                        {
                            str = line.Substring(25,9);
                        }
                        else
                        {
                            str = line.Substring(25 , firstZero - 25) + line.Substring(nonZero , 34 - nonZero);
                        }

Open in new window

0
ddrudikCommented:
You might want to define what you want done with any preceding 0's, if you want to leave any as-is I would try something like this:
Raw Match Pattern:
([1-9]+)(?:0+)?([1-9]+)
 
Raw Replace Pattern:
$1$2
 
C#.NET Code Example:
using System;
using System.Text.RegularExpressions;
namespace myapp
{
  class Class1
    {
      static void Main(string[] args)
        {
          String sourcestring = "source string to match with pattern";
          String matchpattern = @"([1-9]+)(?:0+)?([1-9]+)";
          String replacementpattern = @"$1$2";
          Console.WriteLine(Regex.Replace(sourcestring,matchpattern,replacementpattern));
        }
    }
}
 
$sourcestring after replacement:
6991500

Open in new window

0
nedfineCommented:
It is always good to use your own solutions if it works :) ..  
best of luck in your future encounters with regex   :-)


Thanks
Ned

0
boukakaAuthor Commented:
Good point! thanks
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.