Regexdrill

Level 4: Extraction and cleanup Exercise 56 of 88 Free

A query string parameter

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

Capture the value of the id parameter of a URL in group 1. A parameter starts right after ? or &, and its value runs up to the next & or #, or to the end of the line. Parameters whose name only ends in id, like uid, do not count. The value can be empty.

What this exercise teaches

[?&]id=([^&#]*) ties the name to the start of a parameter, so uid=7 is skipped. The negated class stops the value at the next & or #. The star rather than a plus lets an empty value through.

A hint if you get stuck

Start with a class that holds the two characters a parameter can follow, [?&], then the literal id= and a negated class for the value.

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. The worked solution opens once you solve it or after two tries.

Open this exercise

More exercises in Extraction and cleanup