முக்கிய உள்ளடக்கத்திற்குச் செல்லவும்
eLearner.app
தொகுதி 2 · பாடம் 2 இன் 4பாடத்திட்டத்தில் 6/32~10 min
தொகுதி பாடங்கள் (2/4)

சரியான அளவுகள் `{n,m}`

When you need precise control over the number of repetitions, you use the brace notation {n,m}:

SyntaxMeaning
\d{4}Exactly 4 digits
\d{2,4}From 2 to 4 digits
\d{3,}At least 3 digits

{n} is equivalent to {n,n}. {n,} has no maximum. {,m} is not supported in JavaScript (you must write {0,m}).

Code
Pattern: \d{4}
Sample:  Anni: 2020, 2024, 1999, errore 99.
               ^^^^  ^^^^  ^^^^

{4} stops the match at exactly four digits: 99 does not match because it has only two. 12345 would match the first four digits (1234), not the whole number.

Open intervals and repetition limits

The curly brace notation is flexible: {n} indicates exact repetition, {n,m} a closed range from n to m, while {n,} leaves the upper limit open ("at least n times"). The engine processes these efficiently, reducing the ambiguities of generic quantifiers.

Try it

உடற்பயிற்சி#regex.m2.l2.e1
முயற்சிகள்: 0ஏற்றுகிறது…

Find every 4-digit year in the text (e.g. `2024`, but not `99`).

எடிட்டரை ஏற்றுகிறது…
குறிப்பைக் காட்டு

Exactly 4 digits: use the {4} notation on the \\d class.

3 முயற்சிகளுக்குப் பிறகு தீர்வு கிடைக்கும்

Review exercise

உடற்பயிற்சி#regex.m2.l2.e2
முயற்சிகள்: 0ஏற்றுகிறது…

Find every number made of 2, 3 or 4 digits (excluding 1-digit numbers and numbers 5+ digits long).

எடிட்டரை ஏற்றுகிறது…
குறிப்பைக் காட்டு

Range {2,4}: minimum 2, maximum 4 digits. Without anchors it will also match the first 4 digits of 12345.

3 முயற்சிகளுக்குப் பிறகு தீர்வு கிடைக்கும்

Additional challenge

உடற்பயிற்சி#regex.m2.l2.e3
முயற்சிகள்: 0ஏற்றுகிறது…

Find phone numbers in the format `XXX-XXXX` (exactly 3 digits, dash, exactly 4 digits).

எடிட்டரை ஏற்றுகிறது…
குறிப்பைக் காட்டு

Use curly braces {3} and {4} applied to the \d class.

3 முயற்சிகளுக்குப் பிறகு தீர்வு கிடைக்கும்