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 trialPiotr Manczak
Front End Web Development Techdegree Graduate 29,363 PointsWhy does it work? I tried to match regular expressions.
Why does it work? I tried to match regular expressions: www.github.com github.com www.teamtreehouse.com teamtreehouse.com api.github.com
and exclude those: jsfiddle.net www.jsfiddle.net
I used: ((www.)|(api.)|)(github|teamtreehouse|).com This works but I am not so sure why. Especially this: ((www.)|(api.)|). Joel did not mention in his video case like this. Does it mean www. OR api. OR nothing at all?
1 Answer
Michael Hulet
47,913 PointsIn JavaScript regular expressions, the vertical bar (|
) acts as a logical OR
. The subdomain part of your regular expression (((www.)|(api.)|)
) will match 3 scenarios:
- The string starts with
www.
- The string starts with
api.
- The first character in the string is an empty string (in other words, the string is only either
github.com
orteamtreehouse.com
)
Piotr Manczak
Front End Web Development Techdegree Graduate 29,363 PointsPiotr Manczak
Front End Web Development Techdegree Graduate 29,363 PointsThank you for taking your time to answer that. I suspected that could be the case but I wanted to be sure. Thanks again.