[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

match a pattern in c# using regex

Posted on 2014-03-17
8
Medium Priority
?
531 Views
Last Modified: 2014-03-18
I want to check this pattern

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

Page 1 of 7 280DABC2BB-5ECDC9A0-144B9203297-17F85
0
Comment
Question by:ajaypappan
  • 4
  • 2
  • 2
8 Comments
 
LVL 35

Assisted Solution

by:Terry Woods
Terry Woods earned 400 total points
ID: 39935469
If  you're wanting to capture the full code from the given string, this might work for you:
\d\d([A-Z\d]*-)+[A-Z\d]*

Open in new window


I've assumed "anychars" includes numbers and capital letters at this stage.
0
 
LVL 35

Expert Comment

by:Dan Craciun
ID: 39935472
Don't know about the "Page 1 of 27" part.

For the rest, you can use
@"\d{2}([a-zA-Z0-9]*?-)+[a-zA-Z0-9]*$"

LE: 40 seconds late :)

HTH,
Dan
0
 
LVL 3

Author Comment

by:ajaypappan
ID: 39935520
@"\d{2}([a-zA-Z0-9]*?-)+[a-zA-Z0-9]*$"

this is not capturing the page part. I want the whole thing to be capture starting from page
it can be
 Page * of *  280DABC2BB-5ECDC9A0-144B9203297-17F85

Page 1 of 7 280DABC2BB-5ECDC9A0-144B9203297-17F85
0
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 
LVL 35

Expert Comment

by:Dan Craciun
ID: 39935525
@"Page \d+ of \d+ \d{2}([a-zA-Z0-9]*?-)+[a-zA-Z0-9]*$"
0
 
LVL 35

Expert Comment

by:Terry Woods
ID: 39935529
Page \d+ of \d+ \d\d([A-Z\d]*-)+[A-Z\d]*

Open in new window

0
 
LVL 35

Expert Comment

by:Dan Craciun
ID: 39935574
It can be refined:
"Page [1-9][0-9]* of [1-9][0-9]* [1-9][0-9]([A-Za-z0-9]*-)+[A-Za-z0-9]*"

Open in new window

The page number (or number of pages) should not start with 0. Same for the serial number.
You can remove the "a-z" if you only have capital letters.
0
 
LVL 3

Author Comment

by:ajaypappan
ID: 39936985
The code is matching both strings thats wrong, it should match the first value only

 string fieldValue="280DABC2BB-5ECDC9A0-144B9203297-17F85";
 string fieldValue = "102-33-3639";

I want the whole 3 hyphen to be recognized by the pattern or it will match something else
0
 
LVL 35

Accepted Solution

by:
Dan Craciun earned 1600 total points
ID: 39937047
That was not in the constraints :) This will match only if there are 4 groups of characters, separated by "-"

"Page [1-9][0-9]* of [1-9][0-9]* [1-9][0-9]([A-Za-z0-9]*-){3}[A-Za-z0-9]*"

Open in new window

0

Featured Post

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

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

What my article will show is if you ever had to do processing to a listbox without being able to just select all the items in it. My software Visual Studio 2008 crystal report v11 My issue was I wanted to add crystal report to a form and show…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…

834 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