1. Numbers only
Match a string containing only one or more digits.
Should match: 12345
Should reject: A123, 12-34
Show solution
^\d+$
Anchors force the whole value to be digits.
Practice regular expressions from basic anchors and quantifiers to groups, backreferences, lookahead, and lookbehind. Try each problem before opening the solution.
These practice questions are designed to build one concept at a time and then combine concepts in the final problems.
Match a string containing only one or more digits.
Should match: 12345
Should reject: A123, 12-34
^\d+$
Anchors force the whole value to be digits.
Match DEV- followed by exactly four digits.
Should match: DEV-2026
Should reject: DEV-26, XDEV-2026
^DEV-\d{4}$Literal text plus an exact digit quantifier.
Match file names ending in .jpg, .png, or .gif, ignoring case.
Should match: photo.JPG
Should reject: photo.pdf
\.(?:jpg|png|gif)$
Escape the dot and anchor the extension at the end.
Match ASCII letters only.
Should match: RegexArena
Should reject: Regex2026
^[A-Za-z]+$
A character class plus anchors validates the entire value.
Match both color and colour.
Should match: color, colour
Should reject: colouur
^colou?r$
The question mark makes the preceding u optional.
Match AB12-style codes.
Should match: AB12
Should reject: A123, ab12
^[A-Z]{2}\d{2}$Use exact quantifiers for the two sections.
Match DD/MM/YYYY format only.
Should match: 24/09/2026
Should reject: 2026-09-24
^\d{2}/\d{2}/\d{4}$This checks format, not whether the calendar date exists.
Match a practical email-shaped value.
Should match: dev@example.com
Should reject: dev@site, @example.com
^[\w.-]+@[\w.-]+\.[A-Za-z]{2,}$Useful for practice, but not a complete implementation of email standards.
Match a simple http/https URL with an optional path.
Should match: https://regexarena.com/en/
Should reject: ftp://example.com
^https?://[\w.-]+\.[A-Za-z]{2,}(?:/.*)?$The s is optional; the path group is optional.
Match lines beginning with INFO, WARN, or ERROR followed by YYYY-MM-DD.
Should match: ERROR 2026-09-24 Failed
Should reject: DEBUG 2026-09-24 Trace
^(INFO|WARN|ERROR)\s+\d{4}-\d{2}-\d{2}Alternation captures the allowed log level.
Find every hashtag made of word characters.
Should match: #regex #javascript
Should reject: plain text
#\w+
Use the global flag in JavaScript to collect all occurrences.
Find one or more whitespace characters for replacement.
Should match: a b
Should reject: ab
\s+
Replace each match with a single space.
Capture DEV plus three digits only when it is immediately followed by -OK.
Should match: DEV123-OK
Should reject: DEV123-NO
^DEV\d{3}(?=-OK$)The lookahead checks context without consuming -OK.
Match lowercase names except the exact word admin.
Should match: marcello, regexarena
Should reject: admin
^(?!admin$)[a-z]+$
The negative lookahead rejects one reserved value.
Capture digits only when preceded by R$ and a space.
Should match: R$ 150
Should reject: USD 150
(?<=R\$ )\d+$
The lookbehind checks the prefix without including it in the match.
Capture a code such as DEV-2026 in a named group called code.
Should match: DEV-2026
Should reject: DE-2026
(?<code>[A-Z]{3}-\d{4})Named groups make extracted data easier to understand.
Find a word repeated immediately after itself.
Should match: the the
Should reject: the regex
\b(\w+)\s+\1\b
The backreference \1 repeats the text captured by group 1.
Capture AAA-0000 only after ID: and before ;OK.
Should match: ID:DEV-2026;OK
Should reject: ID:DEV-2026;FAIL
(?<=ID:)(?<code>[A-Z]{3}-\d{4})(?=;OK$)Combine lookbehind, a named group, and lookahead.
RegexArena has 24 interactive levels with positive and negative cases, score, XP, progressive hints, capture-group feedback, and dedicated lookahead/lookbehind missions.