Regex for an alphanumeric word, must be 6 characters long

What is a regular expression for an alphanumeric word, at least 6 characters long (but no more than 50).

+3
source share
3 answers
/[a-zA-Z0-9]{6,50}/

You can use word boundaries at the beginning / end (\ b) if you want to actually combine the word in the text.

/\b[a-zA-Z0-9]{6,50}\b/
+14
source
\b\w{6,50}\b

\w - any character of a β€œword” - depending on the flavor of the regular expression, it may just be [a-z0-9_], or it may include others (for example, accented characters / etc).

{6,50} means from 6 to 50 (inclusive)

\b means the boundary of the word (so that the word does not exceed 50 at both ends).


, , , ? ...

^\w{6,50}$
+8

PCRE :

/[a-zA-Z0-9]{6,50}/

It would be very difficult to do in regex without min / max quantifiers, so I hope your language supports them.

0
source

Source: https://habr.com/ru/post/1699588/


All Articles