Regexdrill

Level 5: Advanced Exercise 43 of 52 Pro

Lookahead: amounts before USD

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

Match every number (with optional decimals) that is followed by a space and USD. The whole match is compared, so it must not include the space or USD.

What this exercise teaches

\d+(?:\.\d+)?(?= USD) requires USD after the number but leaves it out of the match.

A hint if you get stuck

(?=...) checks what comes next without consuming it.

This exercise is part of Pro

Pro unlocks all 52 exercises, with worked solutions and progress saved to your account. The free exercises work without an account.

You create a free account first, so Pro is attached to it.

Monthly is charged today and then every month until you cancel, in one click from your account page. Lifetime is one payment with no renewals. Full refund within 14 days of paying.

Start with the free exercises

More exercises in Advanced