ebarbara
ebarbara

Reputation: 165

Regex started by space and followed by numbers

I'm trying to evaluate a string through regex with the following rules: The string has exactly 5 characters, being the first n whitespaces and the last 5-n (at least 1) numbers.

(\s*\d{1,5}) works, but also matches " 12345", which is very outside of the rules.

Any idea?

Upvotes: 2

Views: 53

Answers (1)

Bohemian
Bohemian

Reputation: 425208

Try this:

^(?=.{5}$)\s*\d+$

The character limit is handled using a look ahead. The rest is straightforward.

See live demo

Upvotes: 4

Related Questions