N
N
nazar-lynovetsky2020-07-06 00:11:45
JavaScript
nazar-lynovetsky, 2020-07-06 00:11:45

What RegExp expression is suitable for checking a string with the following conditions?

Help me write a regular expression to validate a string according to the following conditions:

1. The string can only contain characters - a, b, c, d, e, f.
2. The string can only contain numbers greater than 3 (from the number 3 to infinity).
3. The string must start with an alphabetic character.
4. Repeating (identical) alphabetic characters in a row cannot be more than two.
5. The number cannot be after two consecutive (identical) alphabetic characters. ("aa3" for example, should not pass the test).

For better understanding, here are a few examples:

"abcbdbefab" - TRUE
"eebbaaccddeeff" - TRUE
"f3b4c5d6e712f3" - TRUE
"aab3a3eef" - TRUE

"aaabcccd"
"f7bb6e" - FALSE (cannot be a digit after two identical alphabetic characters in a row)
"3aab5" - FALSE (cannot have a string start with a digit)
"a2b1" - FALSE (cannot use numbers less than 3)

I hope I explained clearly.
I really ask for your help!
Thanks in advance.

Security Code:

const string = "d3bc55aab32ef" // такая строка должна вернуть TRUE так как она подходит под все 5 пунктов
const regExp = ???
return regExp.test(string) // return TRUE

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
dodo512, 2020-07-06
@nazar-lynovetsky

/^(?!.*?([a-f])\1(?:\1|\d))[a-f](?:[a-f]|[3-9]\d*|[12]\d+)*$/

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question