2

Can someone please explain what the following regular expression means?

^(?=.*[\p{L}\p{M}0-9]).{6,50}$

It forces users to have at least one number in their username.

How should I modify it to remove this constraint?

1 Answer 1

1

You need to remove the 0-9 constraint set in the look-ahead:

^(?=.*[\p{L}\p{M}]).{6,50}$

Now, it allows a string containing any symbols but a newline, from 6 to 50 occurrences, and at least one Unicode letter.

To use it in Java, you need to double-escape backslashes:

String pattern = "^(?=.*[\\p{L}\\p{M}]).{6,50}$";
Sign up to request clarification or add additional context in comments.

4 Comments

This was exactly what I tried before posting this question. It does not work. I checked it both on my application and here. Am I missing something?
What language/tool are you using?
This is a web application written in Java.
Java regex is better tested at regexplanet.com, or in the IDE. Here is a demo of what the regex validates in PCRE (it is similar to Java flavor): regex101.com/r/oW0iY2/1. As you see, there must be at least 6 and up to 50 characters and there must be at least 1 letter inside. Also, you must remember that in Java, you need to use double backslashes: String pattern = "^(?=.*[\\p{L}\\p{M}]).{6,50}$";

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.