Find regex string in python

I am new to python and I am trying to cut a piece of string in another string in python. I looked at other similar questions, but could not find the answer.

I have a variable that contains a list of domains that domains look like this:

http://92.230.38.21/ios/Channel767/Hotbird.mp3 http://92.230.38.21/ios/Channel9798/Coldbird.mp3

....

I want the name of the mp3 file (in this example, Hotbird, Coldbird, etc.)

I know I have to do this with re.findall (), but I have no idea about the regular expressions I need to use.

Any idea?

Update: Here is the part I used:

    for final in match2:
         netname=re.findall('\W+\//\W+\/\W+\/\W+\/\W+', final)
         print final
         print netname

What didn't work. Then I tried to do this, which only cut out the ip address (92.230.28.21), but not the name:

    for final in match2:
         netname=re.findall('\d+\.\d+\.\d+\.\d+', final)
         print final
+4
2

str.split():

>>> urls = ["http://92.230.38.21/ios/Channel767/Hotbird.mp3", "http://92.230.38.21/ios/Channel9798/Coldbird.mp3"]
>>> for url in urls:
...     print(url.split("/")[-1].split(".")[0])
... 
Hotbird
Coldbird

, :

>>> import re
>>>
>>> pattern = re.compile(r"/(\w+)\.mp3$")
>>> for url in urls:
...     print(pattern.search(url).group(1))
... 
Hotbird
Coldbird

(\w+) mp3 , aplhanumeric, , mp3 URL-.

+5

?

([^/] * mp3) $

,

...

, mp3, .

, .

0

Source: https://habr.com/ru/post/1609057/


All Articles