Script Valley
Regex: Actually Useful Patterns
Groups and Capturing/Assessment

Practice & Assessment

Test your understanding of Groups and Capturing

Multiple Choice Questions

5
1

Given '2024-06-15'.match(/(\d{4})-(\d{2})-(\d{2})/), what is m[2]?

2

What is the purpose of (?:pattern) in a regex?

3

What does \1 refer to in a regex pattern?

4

Why does 'abc'.match(/[a-z]/g) return ['a','b','c'] but 'abc'.match(/[a-z]/) returns only ['a']?

5

What is the JavaScript syntax for a named capture group that captures a year?

Coding Challenges

1
1

Date Format Converter

Write a function reformatDates(text) that finds all dates in YYYY-MM-DD format in a string and returns the string with those dates rewritten as DD/MM/YYYY.

Easy

Mini Project

1

Log Line Parser

Build a function parseLogLine(line) that uses named capture groups to parse a structured log line.

Medium