简体   繁体   中英

Avoiding Multiple matches in regex

This is the html code:

 [{file: "http://srv74.vidzi.tv/hls2/jjuqjoa4ki2qedz7nlhbttjfjz62mrdkpxryo6zgr,llnmsfgxyea6jqrfama,bb5msfgxyencp5qkgqa,.urlset/master.m3u8"},{file: "http://srv74.vidzi.tv/jjuqjoa4ki2qedz7nlhbttjfjz62mrdkpxryo6zgrbb5msfgxyencp5qkgqa/v.mp4"}]

My intention is to extract the link ending with v.mp4

My regex is as follows:

(http://srv74.vidzi.tv/.+?/v.mp4)

However, I get both urls as matches in my regex How do I avoid multiple matches?

I am using pythex

You can't get around using a common start position unless you exclude
it when using the dot . character.

This is the more reliable way.
Doing this you don't have to worry about valid url chars or
whether there are possibly other separators.

(http://srv74\\.vidzi\\.tv/(?:(?!srv74\\.vidzi\\.tv).)+?/v\\.mp4)

https://regex101.com/r/xrnuZw/1

Expanded

 (                             # (1 start)
      http://srv74\.vidzi\.tv/
      (?:
           (?! srv74\.vidzi\.tv )        # Don't let this be before mp4
           . 
      )+?
      /v \. mp4 
 )                             # (1 end)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM