0
https://fire.vimeocdn.com/1485599447-0xf546ac1afe7bce06fa5153973a8b85b1c45051d3/159463108/video/499604330/playlist.m3u8

I want to Include Everything Except playlist.m3u8

(playlist.[^.]*)

is selecting "playlist.m3u8", i need to do exactly opposite.

Here is an Demo. https://regex101.com/r/RONA65/1

Rahul Sharma
  • 779
  • 2
  • 12
  • 27

3 Answers3

1

You can use positive look ahead:

(.*)(?=playlist\.[^.]*)

Demo:

https://regex101.com/r/RONA65/4


Or you can try it like this as well:

.*\/

Demo:

https://regex101.com/r/RONA65/2

Regex:

.*\/ Select everything till last /

Mohammad Yusuf
  • 16,554
  • 10
  • 50
  • 78
0

You can use the split function:

>>> s = 'https://fire.vimeocdn.com/.../159463108/video/499604330/playlist.m3u8'
>>> '/'.join(s.split('/')[:-1])
'https://fire.vimeocdn.com/.../159463108/video/499604330'

Or simpler with rsplit:

>>> s = 'https://fire.vimeocdn.com/.../159463108/video/499604330/playlist.m3u8'
>>> s.rsplit('/', 1)[0]
'https://fire.vimeocdn.com/.../159463108/video/499604330'
Maurice Meyer
  • 17,279
  • 4
  • 30
  • 47
0

Use non-greedy match by adding '?' after '*'

import re
s = 'https://fire.vimeocdn.com/1485599447-0xf546ac1afe7bce06fa5153973a8b85b1c45051d3/159463108/video/499604330/playlist.m3u8'
m = re.match('(.*?)(playlist.[^.]*)', s)
print(m.group(1))
gzc
  • 8,180
  • 8
  • 42
  • 62