Extracting Domains from URLs

Screen link:https://app.dataquest.io/m/369/advanced-regular-expressions/8/extracting-domains-from-urls
Hello everyone. The eighth slide in the Advanced Regular Expression mission got me all confused. Can someone explain how the pattern provided by the answer matches the expected? I used a different pattern, that achieved the same result, but for me, the provided answer makes no sense.
The code: (pattern 1 is provided by DQ’s answer)
1

How I made my pattern:

Using the same tool with the provided pattern:

Thanks in advance =)
Edit: The site I used for testing the regex is https://regex101.com/
Edit 2: Actually I thought it would work, lol. I got this error, which is odd, since the ‘top_domains’ variable uses ‘domains’ and it is correct.

It is very likely that this question has been asked and answered in the past.

If you provide a link to this screen, I’ll find the other topics around this for you. Please add it to your original post.

Thanks for replying, I added the screen link. But besides the reasoning for the pattern provided, I would also like to know why it doesn’t work in the website that I’m using . (picture 3)

Nope, you added a community link. Can you please fix this?

There are several regex engines. Although your screenshot doesn’t show everything, it looks like you’re not using the Python engine (selectable on the left). You’re probably using PCRE, which is the default.

Please add some text to your question, it’s hard reading from screenshots and it doesn’t allow one to copy and paste your code for reproduction.

1 Like

This actually clears everything. Thanks a lot =))
I added the proper screen link anyway.
Thanks again

Great! Thanks for adding the link.

Hi Bruno, I am trying to use the pattern = r’https?://([\w-]+.[\w-]+.?[\w-]?)’ for this exercise which actually gives the result correctly but it is not allowing to submit and pass the exercise. When I checked in the site regex101, it is matching the URLs correctly. Could you please help me to identify what is wrong in the solution of mine. Thanks.

That seems like a different question, so please ask it in a new topic.

1 Like