S
S
snxx2021-07-23 23:08:23
Python
snxx, 2021-07-23 23:08:23

Is the regex correct?

Information:
There is a certain site where I get data (video). The parsing function works fine if you provide a link in requests.get(url). But I want to use this function elsewhere in the future, so I need a regular expression so that I expect different values ​​from the user, and everything works without interruption.

Description:
There is this link: https://example.com/serial/season-2/episode-3.html and https://example.com/serial/episode-1.html .
That is, the fact is that the links are different, some links do not have the season-X part (instead of X, any number). And the problem with seasons and episodes is that they can reach 200, or 10, different.

url = r'^https://(example\.com)/\w+/(episode-\d+|season-\d+/episode-\d+).html$'

And of course, there is .html at the end of every link, and nothing else.

You can help format the regular expression and explain your change.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Viktor Taran, 2021-07-23
@lppxx

So ?
https://regex101.com/r/TXEFg5/1

N
Nadim Zakirov, 2021-07-23
@zkrvndm

Use the question mark quantifier to indicate that some part of the regular expression may or may not be present.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question