WeChall - Training - Regex
Challenge
4-level regex training on WeChall. Each level requires the
shortest possible regex pattern, submitted with
delimiters (e.g. /pattern/).
Solution
Level 1 — match empty string: /^$/
Level 2 — match the string "wechall" exactly:
/^wechall$/
Level 3 — match image filenames wechall.ext or
wechall4.ext with valid extensions (jpg, gif, tiff, bmp,
png):
1 | /^wechall4?\.(?:gif|tiff|png|jpg|bmp)$/ |
4?makes the4optional (wechall or wechall4)(?:...)non-capturing group for the extensions (shortest possible)
Level 4 — same as L3 but capture the filename without extension:
1 | /^(wechall4?)\.(?:gif|tiff|png|jpg|bmp)$/ |
(wechall4?)capture group returnswechallorwechall4