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

வகுப்புகளுக்குள் வரம்புகள்: `[a-z0-9]`

Listing every character one by one is tedious. Classes accept ranges with the hyphen -: [a-z] matches any lowercase letter, [0-9] a digit, [A-Z] an uppercase letter.

Code
Pattern: [a-z]+
Sample:  Ciao Mondo 123
          ^^^  ^^^^

The range uses code point order (essentially ASCII for Latin characters): a-z means "every character from the code point of a to the code point of z", so 26 letters.

Combining ranges

Inside a single class you can mix multiple ranges and individual characters:

Code
[a-zA-Z0-9_]   identical to \\w (in ASCII)
[a-fA-F0-9]    hexadecimal digits
[0-9.]         digits or the dot (for decimal numbers)

Order does not matter: [0-9a-z] and [a-z0-9] are identical.

Ranges and ASCII character order

Ranges like [a-z] strictly follow the character order in the ASCII table. Writing an invalid range, such as [z-a], will trigger a regex compilation error. A literal dash should be placed at the start or end: [a-z-].

Try it

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

Find every hexadecimal sequence of 6 characters (e.g. the color code #1a2b3c). Digits go from 0 to 9, letters from a to f (uppercase or lowercase).

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

Add A-F to the range, or use the i flag.

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

Review exercise

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

Find every product code made of 3 uppercase letters followed by 4 digits (e.g. ABC1234).

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

For digits you can use \\d or the range [0-9]: this exercise requires explicit [0-9].

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

Additional challenge

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

Find hex characters in the text (digits 0-9 and letters A-F, both upper and lowercase).

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

Combine three ranges: 0-9, a-f, A-F.

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