RichardW1
RichardW1

Reputation: 1

Limitation of spaces in regex string

Total regex newbie here and I have been all over the place to try and find an answer. I need to add exactly 1 space followed by a string of letter characters (min 3 max 30) I have the following but it will accept more than 1 space which is the problem:

^[:blank:][A-z]{3,30}$

Any help with this would be great

Upvotes: 0

Views: 51

Answers (2)

Wiktor Stribiżew
Wiktor Stribiżew

Reputation: 626903

[A-z] will also capture [, \, ], ^, _, `.

Use this regex to allow exactly 1 space in the beginning and then 3 to 30 English letters:

^[[:blank:]][a-zA-Z]{3,30}$

See demo.

enter image description here

Upvotes: 2

Toto
Toto

Reputation: 91430

To be unicode compatible:

^\p{Zs}\p{L}{3,30}$

Where \p{Zs} stands for a space character
and \p{L} stands for a letter.

Upvotes: 0

Related Questions