RegexWars
Tier 7 · Apprenticecapture

Just The Extension

Capture the file extension of a filename: report.q3.pdf gives pdf, not q3.pdf.

Your first capture group. Round brackets mark the part of the match you want handed back — capture mode compares group 1, group 2 and so on against the expected list, and the rest of the match is just there to find the right spot. The trap is the dot: a filename can have several, and you want the LAST one. Anchoring the end with $ is what forces the engine past the earlier dots. A name with nothing after the final dot has no extension at all, so it should not match.

Your pattern0 chars · par 8
//
Flags
Start typing — tests run as you go.0 of 4 visible tests passing
Test cases
  • report.q3.pdf→ ["pdf"]

    two dots — you want the last one

  • notes.txt→ ["txt"]
  • archive.tar.gz→ ["gz"]
  • READMEmust not match

    no dot, no extension

+ 3 hidden tests, checked when you submit. They are what stops a pattern that only fits the examples above.