Solved

match a pattern in c# using regex

Posted on 2014-03-10
3
352 Views
Last Modified: 2014-03-30
I want to check this pattern

start with atleast 2 digits and a hyphen
like number number, anychars [hyphen]..repeat to match below string

280DABC2BC-227D8A97-144822B5BB0-17F42


here is what i did
            string fieldValue = "280DABC2BC-227D8A97-144822B5BB0-17F42";
               string pattern = @"(\d*[-])";
                Regex r = new Regex(pattern, RegexOptions.IgnoreCase);
                Match m = r.Match(fieldValue);
                if (m.Success)
                {
                    console.writeline "match found";

                }
0
Comment
Question by:ajaypappan
  • 2
3 Comments
 
LVL 34

Accepted Solution

by:
Dan Craciun earned 500 total points
ID: 39918057
If there's always going to be 4 groups, try this:
@"(\d{2}[A-Z0-9]*-){3}\d{2}[A-Z0-9]*$"

Open in new window


HTH,
Dan
0
 
LVL 34

Expert Comment

by:Dan Craciun
ID: 39918298
Please read the grading guide: http://support.experts-exchange.com/customer/portal/articles/481419

The short story: if you give a grade other than A, you are required to post an explanation on what was deficient about the solution.

Thank you.
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

762 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

15 Experts available now in Live!

Get 1:1 Help Now