splitt string with regex with c#

Hello everybody,

i have the the following two strings:

D 1069 Dresden - Neustadt
01069 Dresden - Neustadt

I want to splitt the string with c# and the result should be in both cases:

1069
Dresden - Neustadt

How could i do this with regular expression?

thank you very much
Kind regards
bounty
LVL 1
bounty457Asked:
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.

Terry WoodsIT GuruCommented:
Try doing a match with the following pattern (multiline mode turned on):
([1-9]\d*) (.*$)

Open in new window

It will capture the text for each line into separate groups.

I'm not a C# programmer, but the myregextester.com website generated the following code. Hopefully that helps.
using System;
using System.Text.RegularExpressions;
namespace myapp
{
  class Class1
    {
      static void Main(string[] args)
        {
          String sourcestring = "source string to match with pattern";
          Regex re = new Regex(@"([1-9]\d*) (.*$)",RegexOptions.Multiline);
          MatchCollection mc = re.Matches(sourcestring);
          int mIdx=0;
          foreach (Match m in mc)
           {
            for (int gIdx = 0; gIdx < m.Groups.Count; gIdx++)
              {
                Console.WriteLine("[{0}][{1}] = {2}", mIdx, re.GetGroupNames()[gIdx], m.Groups[gIdx].Value);
              }
            mIdx++;
          }
        }
    }
}

Open in new window

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
bounty457Author Commented:
Great, it works Thank you very much.
Kind regards
bounty
0
bounty457Author Commented:
I've requested that this question be closed as follows:

Accepted answer: 0 points for bounty457's comment #a40287489

for the following reason:

Thank you for the fast solution.
0
käµfm³d 👽Commented:
I'm thinking you mean to accept Terry's comment as the solution?
0
bounty457Author Commented:
Hello eenookami,

yes i accept Terry's comment as solution, I have clicked on "accept as solution" but i can't select the points. There was no link or button available.

Thank you for accepting as solution with 500 points.
kind regards
bounty
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.