Itniv Itniv - 1 month ago 25
C# Question

Regex for 550-5.1.1 c#

How do I write a Regex for this format "550-5.1.1"
Update : I thought my question was clear, still making it more elaborate

I need to write a Regex for accepting 3 integers then a '-' and 1 integer then a '.' and 1 integer then a '.' and 1 integer

WWW-X.Y.Z

WWW 3 digit integer,
X 1 digit integer,
Y 1 digit integer
Z 1 digit integer

Answer

If you are suggesting that you will always have 3 digits, a dash and then always 1 digit from then on, this will work

^\d{3}-\d\.\d\.\d$

if you will have, say, 1 to 4 in the first section you can have this

^\d{0,4}-\d\.\d\.\d$

as you seem new to Regex, here's an explanation

^ - start of the string
\d - a digit
{3} - exactly three of the preceding object
- A literal dash character
\. - an escaped '.' character, as . unescaped can match any character.
$ - end of the string
Comments