dmxyler
dmxyler

Reputation: 79

Regex starts with ends with

I can't figure out how to write a regex expression that finds a specific string that starts with, for example, https:// and ends with .m3u8

I managed to write a regex expression that highlights the specific part of the string that contains the .m3u8 tag

^(.*?(\m3u8\b)[^$]*)$

But I need to write an expression that highlights the whole string.

enter image description here

Added example text as well

INPUT

poster":"https://test/four/v1/video-file1/00/00/00/00/00/00/00/10/22/11/102211-480p.mp4/thumb-33000.jpg","content":{"mp4":[],"dash":"https://test/four/v1/video-file1/00/00/00/00/00/00/00/10/22/11/102211-,480,p.mp4.urlset/manifest.mpd","hls":"https://test/four/v1/video-file1/00/00/00/00/00/00/00/10/22/11/102211-,480,p.mp4.urlset/master.m3u8"},"about":"false","key":"4eeeb77181526bedc1025586d43a70fa","btn-play-pause":"true","btn-stop":"true","btn-fullscreen":"true","btn-prev-next":"false","btn-share":"true","btn-vk-share":"true","btn-twitter-share":"true","btn-facebook-share":"true","btn-google-share":"true","btn-linkedin-share":"true","quality":"true","volume":"true","timer":"true","timeline":"true","iframe-version":"true","max-hls-buffer-size":"10","time-from-cookie":"true","set-prerolls":["https://test/j/v.php?id=645"],"max-prerolls-impressions":1});

OUTPUT:

https://test/four/v1/video- 
file1/00/00/00/00/00/00/00/10/22/11/102211-,480,p.mp4.urlset/master.m3u8

CAUTION: There are two other HTTP links as well

https://test/four/v1/video- 
file1/00/00/00/00/00/00/00/10/22/11/102211-,480,p.mp4.urlset/manifest.mpd

And,

https://test/four/v1/video-file1/00/00/00/00/00/00/00/10/22/11/102211-480p.mp4/thumb-33000.jpg

They must not be highlighted by regex because they start with http but they don't end with .m3u8

Upvotes: 2

Views: 18523

Answers (2)

Robo Mop
Robo Mop

Reputation: 3553

You could try:

https:\/\/[^"]+?\.m3u8

As shown here

Explanation -

Since your desired string won't contain double quotes ",

[^"]+? is a non-greedy (lazy) regex which matches one-or-more characters between https:// and .m3u8 which are not "

And do note how I've used ? after [^"]+ so that it doesn't match any other links too.

Also, \. matches a full-stop, while just . would have matched any character.

Upvotes: 6

Ami Heines
Ami Heines

Reputation: 500

How about this:

https:\/\/.*\.m3u8

It looks for:

  1. an exact match of https://
  2. followed by .* which means, "any characters will match..."
  3. followed by the exact match for .m3u8

This should highlight the complete string.

Upvotes: 2

Related Questions