Mikayil Abdullayev
Mikayil Abdullayev

Reputation: 12367

What does this regular expression mean?

could somebody please tell me what the following expressions means:

\d{6,8}

As far as I know it's a regular exp

Upvotes: 0

Views: 1683

Answers (5)

Gaijinhunter
Gaijinhunter

Reputation: 14685

It means between 6 to 8 numbers in a row.

  • \d means a number [0-9]
  • {6, 8} means min. of 6, max. of 8

You use curly braces to describe how many of the previous character you want to look for. Entering a single number, like {3} means 3 in a row. Adding a second number changes this into min/max.

http://www.regular-expressions.info is the best site on the web for learning about regular expressions.

Upvotes: 1

Antony Scott
Antony Scott

Reputation: 21998

it means, at least 6 digits and no more than 8 digits

Upvotes: 1

netbrain
netbrain

Reputation: 9304

matches a digit that is of length between 6 and 8

Upvotes: 1

Nate
Nate

Reputation: 12819

it matches between 6 and 8 sequential numeric digits.

\d is equivalent to the character class [0-9], and the {,} notation specifies an exact number of times that a pattern has to match.

Upvotes: 2

David Precious
David Precious

Reputation: 6553

Between 6 and 8 numeric digits.

(As it's not anchored to boundaries or start & end of string, it would also match between 6 and 8 digits within a longer series of digits - for instance, it will match 123456, 1234567, 1234678, but also the first 8 digits of 123456789.)

\d is a character class - it could also have been written as [0-9]. The {} part is a repetition count; it could be a single number, e.g. {6}, or, as in this case, a range - so the {6,8} means "the previous thing, repeated between 6 and 8 times".

Upvotes: 5

Related Questions