Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript Regular Expressions in JavaScript Regular Expressions Groups

Aakash Srivastav
Aakash Srivastav
Full Stack JavaScript Techdegree Student 11,626 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
221,293 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,919 Points

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