0

I am trying to create a Regex for a string where following rule is applied

  1. I need to validate the string only if first 1-3 characters (it can be 1 char,2 char or 3 char ) are numeric and after that it has a '/' symbol character
  2. If the 1st condition meets then i need to check whether the characters after that '/' should be any one of the following chars only ('ADD.','MOD.'), if not it should fail
  3. If the 1st condition doesnot meets then it should not validate the string.

i tried with this regex but i am not able to get the solution.

(?=^[0-9]{1,3}[/]{1})^[0-9]{1,3}[/]{1}[(ADD.|MOD.)]{4}|(.*)

the condition doesnot fails when i validate a string - '123/testing' it should fail

Please let me know what i am missing.

Kind Regards, D.Mahesh

1 Answer 1

2

Why don't you use this regex:

^\d{0,3}/(ADD\.|MOD\.)

Like this:

string regex = @"^\d{0,3}/(ADD\.|MOD\.)";
Sign up to request clarification or add additional context in comments.

4 Comments

hi amit just modified the question
the starting char can be any numeric char and it can be 1/ or 34/ or 980/ if is satisifies this condition then i need to check rest of characters otherwise i donot need to check rest of the characters in the string
thnx for ur prompt reply and help i tried ur regex with the following examples but still no luck -123/test 6/MOD.1test 126/MOD.1test 60/MOD.1test abc/MOD.1test 60MOD.1test 6/MOD1 12ts/ADD. i am testing with regexlib tester in the above example s all are valid string only 123/test is an invalid string
i tried with regex still no results i think somewhere i am making mistake in using conditional regex

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.