pattern = r"https?://([\w-.]+)"
I wondering about this regex “([\w-.]+)”
can anyone help to make me understand?
pattern = r"https?://([\w-.]+)"
I wondering about this regex “([\w-.]+)”
can anyone help to make me understand?
Can you help us understand your question?
Sorry. I tried to understand this regex as below when I learned that course.
Can you help me to explain it?
pattern = r"https?://([\w-.]+)"
I don’t understand r"https?://([\w\-\.]+)
" the bold characters
\w
is shorthand for [a-zA-Z0-9_]
and \-
matches a dash (-
) and \.
matches a dot (.
), all 3 of which are commonly use in urls (and we can combine them into \w-.
.
The +
in regex matches a string that contains one or more of the symbols contained within [a-zA-Z0-9_]
.
The square brackets are a character class as mentioned in the article above.
We will still need to include the word boundary to be match (i.e., the rounded brackets (
and )
).
I suggest you revisit the lesson again and check out the documentation if you have any other doubts.