ప్రధాన కంటెంట్‌కు వెళ్లండి
eLearner.app
మాడ్యూల్ 5 · 4లో పాఠం 1కోర్సులో 17/32~8 min
మాడ్యూల్ పాఠాలు (1/4)

అక్షర సమితులు: `[abc]`

When a predefined class like \d or \w is not enough, you can define a custom character set with square brackets [...]. Inside the brackets, each character is an alternative: the regex matches one of any of the listed elements.

Code
Pattern: [aeiou]
Sample:  ciao mondo
         ^   ^^  ^^

Each vowel is a match on its own. Brackets match exactly one character (unless quantified): [aeiou]+ matches a contiguous sequence of vowels.

Special characters inside brackets

Inside [...] most meta-characters lose their special meaning:

  • . inside [.] matches a literal dot (no escape needed).
  • *, +, ?, (, ), {, } are literal.
  • \ ] ^ instead remain special and must be escaped or carefully positioned.
Code
Pattern: [.,;:]
Match: any punctuation mark among dot, comma, semicolon, colon.

Special characters inside square brackets

Most regex meta-characters (., *, +, ?, etc.) lose their special meaning inside brackets and are treated as literal characters. Only the dash -, the caret ^ at the start, and the backslash \\ retain operational meanings.

Try it

వ్యాయామం#regex.m5.l1.e1
ప్రయత్నాలు: 0లోడ్ అవుతోంది...

Find every vowel (a, e, i, o, u, including uppercase) in the text, one by one.

ఎడిటర్ లోడ్ అవుతోంది…
సూచనను చూపించు

Add the uppercase vowels inside the brackets, or use the i flag.

3 ప్రయత్నాల తర్వాత పరిష్కారం లభిస్తుంది

Review exercise

వ్యాయామం#regex.m5.l1.e2
ప్రయత్నాలు: 0లోడ్ అవుతోంది...

Find punctuation marks: dot, comma, semicolon, colon, exclamation mark, question mark.

ఎడిటర్ లోడ్ అవుతోంది…
సూచనను చూపించు

Inside [.,;:!?] all characters are literal, no escaping needed.

3 ప్రయత్నాల తర్వాత పరిష్కారం లభిస్తుంది

Additional challenge

వ్యాయామం#regex.m5.l1.e3
ప్రయత్నాలు: 0లోడ్ అవుతోంది...

Find all Italian accented vowels (`àèéìòù`) in the text.

ఎడిటర్ లోడ్ అవుతోంది…
సూచనను చూపించు

List the accented letters inside square brackets.

3 ప్రయత్నాల తర్వాత పరిష్కారం లభిస్తుంది