How using the conditions in the regex

Tell us what’s happening:
Describe your issue in detail here.

Your code so far

let username = "JackOfAllTrades";
let userCheck = /^[A-Za-z][^0-9][A-Za-z][0-1]?/; // Change this line
let result = userCheck.test(username);

Your browser information:

User Agent is: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.159 Safari/537.36

Challenge: Restrict Possible Usernames

Link to the challenge:

Hello there.

Do you have a question?

If so, please edit your post to include it in the Tell us what’s happening section.

Learning to describe problems is hard, but it is an important part of learning how to code.

Also, the more information you give us, the more likely we are to be able to help.

if you mean ‘this or that’ , you can use the “|” operator, so /this|that/ will match either “this” or “that”.

i want to know how to check a condition to run a regex give

the test method confront a string with the regex and returns true or false depending if it matches or not

I am using the ternary condition to check my state before using the regex

what ternary condition? what state? the Restrict Possible Usernames challenge does not have such things. What code are you talking about?

I did like this

let sampleWord = "astronaut";
let pwRegex = (/\D/.test(sampleWord))? /(?=\w{5,})(?=\D*\d{2,})/ : /\D/;
let result = pwRegex.test(sampleWord);

can yoiu explain the logic of your code in your own words?