Two captures: major and minor version
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
Find the first version tag written v, a number, a period and a number, like v2.14. Capture the major number in group 1 and the minor number in group 2. A v that is not followed by exactly that shape does not count.
What this exercise teaches
v(\d+)\.(\d+) captures the two numbers in order. With an unescaped period, v1x2 would also count, and without the v the pattern would pick up any decimal number earlier on the line.
A hint if you get stuck
Groups are numbered by their opening parenthesis, left to right. Escape the period between the two numbers.
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 Groups and alternation
- Alternation: cat, dog or birdFree
- Alternation with anchorsFree
- Capture a standalone yearFree
- Group without capturingFree
- Backreference: doubled wordsFree
- Matching quote marksFree
- Optional group: phone extensionFree
- Repeated group: dotted numbersFree
- Alternation inside a groupFree
- Grouped alternatives: Mr, Mrs, Ms, DrFree
- Alternation precedence: image file namesFree
- Backreference: a doubled letterFree