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

வைல்டு கார்டு: புள்ளி `.`

The dot . in regex is the wildcard: it matches any single character\u2026 with one important exception: it does NOT match the newline (\n).

Code
Pattern: c.t
Sample:  cat cot cut c@t c\nt
         ^^^ ^^^ ^^^ ^^^

Three letters: a c, any character, a t. No newline in between, so c\nt is not matched (by default).

The dot is extremely useful but also dangerous: used without discipline it captures more than you intended. Combined with the quantifiers in module 2 (.*, .+?) it is the source of 90% of patterns that "don't work the way I expected".

The s flag: "dotAll"

With the s flag (also called dotAll or single-line) the dot matches every character, newline included. Useful to extract blocks that span multiple lines.

Code
Pattern: <p>.*</p>
Flag:    gs
Sample:  <p>prima\nseconda</p>
         ^^^^^^^^^^^^^^^^^^^^^

Limits and behavior of the dot wildcard

The dot . is a powerful wildcard, but by default it does not match newline characters (\\n). If you want the dot to match absolutely everything, including newlines, you must enable the s (dotAll) flag. Be careful when combining the dot with quantifiers (.*), as it tends to consume too much text (greedy behavior).

Try it

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

Find every triplet of characters delimited by parentheses, e.g. `(abc)`, `(xyz)`. Use the wildcard for the 3 inner characters.

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

Three dots for three arbitrary characters. The parentheses are meta-characters: they must be escaped with \\.

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

Review exercise

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

Extract the block between `[INIZIO]` and `[FINE]`, which can span multiple lines. You will need the `s` flag so the dot also matches newlines, and the 'lazy' version of the quantifier (`.*?`, module 2).

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

Without the s flag, the dot stops at end of line: add it. The form .*? (lazy) stops the match at the first [FINE].

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

Additional challenge

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

Find all 3-character sequences starting with `c` and ending with `t` (e.g. `cat`, `cot`, `c-t`).

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

The pattern uses the dot '.' to represent the wildcard middle character.

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