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 trial

JavaScript Regular Expressions in JavaScript Regular Expressions Groups

Aakash Srivastav
seal-mask
.a{fill-rule:evenodd;}techdegree
Aakash Srivastav
Full Stack JavaScript Techdegree Student 11,638 Points

Regular Expressions - Groups

Can I use this (www.)?google(.net|.com) Because , it also does the same thing .
My next question is when I have included "dot" character inside the parenthesis , do will still need to use "backslash" character?

2 Answers

Steven Parker
Steven Parker
231,269 Points

Without the backslash, a period (dot) matches any character. The backslash cancels the special meaning and causes it to match only an actual period.

This is necessary to prevent the pattern from matching other things that it is not intended to match.

For example, the pattern shown above would match "wwwagoogleynet".

Steve Gallant
Steve Gallant
14,943 Points

To clarify, the exception being when the period (dot) is within square brackets, per a previous video.