Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialkaran Badhwar
Web Development Techdegree Graduate 18,135 PointsHow /(\d*)(\d{2})/ this works
For example the number is 5347 but the first part (\d*) can capture all the 4 digits, so can it just skip the Second part (\d{2}) or the whole expressions evaluates which part to distribute to which section?
1 Answer
Brian Jensen
Treehouse StaffGreat question karan karan!
The two sets of parenthesis ()
are creating 2 capture groups. That way you can access the first 2 digits and the last 2 digits of that 4 digit string independently, with $1
and $2
.
karan Badhwar
Web Development Techdegree Graduate 18,135 Pointskaran Badhwar
Web Development Techdegree Graduate 18,135 PointsHello Brian Jensen, So this means the regex with 2 parenthesis, informs the parser to expect two stored groups right?
Brian Jensen
Treehouse StaffBrian Jensen
Treehouse StaffExactly karan karan