0

I have the following regex to match this:
U$MichaelU$P@$asdqwe123P@$ - this is correct; the other two are not
U$NameU$P@$PasswordP@$
U$UserU$P@$ad2P@$

A registration is valid when:

  • The username is surrounded by "U$"
  • The username needs to be minimum 3 characters long, start with an uppercase letter, followed only by lowercase letters
  • The password is surrounded by "P@$"
  • The password needs to start with minimum 5 alphabetical letters (not including digits) and must end with a digit

My regex is

@"^(U\S)([A-z][a-z]{3,})\1(P@\S)([a-z]{5,}[^\d])([\d]+)\3$"

The problem is that it matches the first one but when I submit to the judge it passes first 2 test but the rest it breaks, could you please tell me where is my mistake.

9
  • could you reformat your question? Commented Dec 3, 2019 at 10:40
  • 1
    describe a bit what you want to match Commented Dec 3, 2019 at 10:44
  • You could go and use String.Split, first with "U$" and then with "P@$" instead of a regular expression Commented Dec 3, 2019 at 10:44
  • A registration is valid when: - The username is surrounded by "U$" - The username needs to be minimum 3 characters long, start with an uppercase letter, followed only by lowercase letters - The password is surrounded by "P@$" - The password needs to start with minimum 5 alphabetical letters (not including digits) and must end with a digit Commented Dec 3, 2019 at 10:45
  • Don't use \S to match a $. \S matches many other characters as well. Also, the regex looks for a minimum of 4 letters in the name, not 3, and 6 non-digits in the password, not 5. Commented Dec 3, 2019 at 10:48

1 Answer 1

2

Hello your regex must be

@"^(U\S)([A-Za-z]{3,})\1(P@\S)([A-Za-z0-9]{5,})\3$"

it works for you

Sign up to request clarification or add additional context in comments.

3 Comments

U$NameU$P@$PasswordP@$ it count thaht one too and it dosnet have to do it
@"^(U\S)([A-Z]{1}[a-z]{2,})\1(P@\S)([A-Za-z]{4,}[0-9]{1,})\3$" you want this but it's dont count U$UserU$P@$ad2P@$
thats the one now only one test dosent pas from 12

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.