Saeed mohammadi
Saeed mohammadi

Reputation: 319

Repeating an expression group

([a-z]+\w*){5}

Above expression matches every text that:

  1. Has at least 5 a-z characters
  2. Has not begun with non a-z characters
and that's not what I want to express.

It doesn't care about whole string length (It matches "abc123456deftjfklajdfkj239")

I want an expression that matches with a text that :

  1. starts with a-z characters
  2. Continues with word characters
  3. whole string's length won't be more than 5 character

Upvotes: 0

Views: 24

Answers (1)

Explosion Pills
Explosion Pills

Reputation: 191819

Use anchors to do this:

^[a-z]\w{,4}$

http://rubular.com/r/xdqYajifZa

Upvotes: 2

Related Questions