Shorthand classes: a word, a space, a number
A regex exercise from Regexdrill. Solve it with a pattern box with live highlighting in your browser, checked against hidden test strings, and it is checked the moment you submit.
The task
The whole line must match. Match one word made of letters, digits or underscores, then exactly one space, then one or more digits, like item 42.
What this exercise teaches
\w+ \d+ takes a run of word characters, one literal space and a run of digits. Because the whole line must match, a second word, a hyphen or a second space makes the line fail.
A hint if you get stuck
\w is any word character (a letter, digit or underscore) and \d is any digit. Repeat each with +.
Try it now, free, no account needed
Every exercise on Regexdrill is free to try. Open it on the practice page, solve it, and get instant feedback with a hint. A free account adds the worked solution; Pro adds timed mode and the certificate.
Open this exerciseMore exercises in Basics
- Find a literal wordFree
- The dot matches one characterFree
- Character class: gray or greyFree
- Ranges: a letter and two digitsFree
- Negated class: no vowelsFree
- Counted repeats: 3 to 5 digitsFree
- One or more: goal, gooal, goooalFree
- Optional letter: color or colourFree
- Anchors: lines that start with ERRORFree
- Escaping: a price like $4.99Free
- Anchors: lines that end with a periodFree