• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 533
  • Last Modified:

match a pattern in c# using regex

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
ajaypappan
Asked:
ajaypappan
  • 4
  • 2
  • 2
2 Solutions
 
Terry WoodsIT GuruCommented:
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
 
Dan CraciunIT ConsultantCommented:
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
 
ajaypappanAuthor Commented:
@"\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
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
Dan CraciunIT ConsultantCommented:
@"Page \d+ of \d+ \d{2}([a-zA-Z0-9]*?-)+[a-zA-Z0-9]*$"
0
 
Terry WoodsIT GuruCommented:
Page \d+ of \d+ \d\d([A-Z\d]*-)+[A-Z\d]*

Open in new window

0
 
Dan CraciunIT ConsultantCommented:
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
 
ajaypappanAuthor Commented:
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
 
Dan CraciunIT ConsultantCommented:
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

Take Control of Web Hosting For Your Clients

As a web developer or IT admin, successfully managing multiple client accounts can be challenging. In this webinar we will look at the tools provided by Media Temple and Plesk to make managing your clients’ hosting easier.

  • 4
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now