How to create a regular expression that requires 4 characters and spaces?

I try to have the user enter exactly 4 characters without spaces ... this is what I have:

.[^\s]{4}

but everything I entered says it doesn't match the regex ...

Where am I going wrong?

+3
source share
6 answers

Why is there another one ahead .? This will match a single character before your β€œfour spaces” are counted.

You might also want to associate it with the beginning and end of a line, so:

^[^\s]{4}$
+14
source

, , \S, \S, . , :

^[\S]{4}$

:

^ -

[/S] - "S"

{4} - 4

$-

+9
\S{4}

4 . # regex, Expresso.

+1

Java:

[^\s]{4,4}
+1

- /^ [^\s] {4} $/

0
0

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


All Articles