Home > Net >  Regex pattern to find string after second occurrence
Regex pattern to find string after second occurrence

Time:12-07

I have a string like below.

#EXTINF:-1  tvg-id=ts191  tvg- 
logo=http://188.155.56.49/jumpstart/Temp_Live/cdn/HLS/Channel/imageContent-795-j5m7axrc- 
v1/imageContent-795-j5m7axrc-m1.png   group-title=Entertainment,   DD National
#KODIPROP:inputstream.adaptive.license_type=com.widevine.alpha 
#KODIPROP:inputstream.adaptive.license_key=https://tatasky.live.ott.irdeto.com/Widevine/getlicense?_session=y249xI2vioV2INEcjlJg4u7JC
https://delta12tatasky.akamaized.net/out/i/3569776.mpd

I'm looking for regex pattern to find link which is after licence_key link. I have tried below pattern but it's giving first link only.

(?<=#KODIPROP:inputstream.adaptive.license_key=).*

I just want https://delta12tatasky.akamaized.net/out/i/3569776.mpd as result.

Live copy available here Regexer Link to check.

CodePudding user response:

You may use this regex for getting next line after a given fixed pattern:

#KODIPROP:inputstream\.adaptive\.license_key=.*\r?\n\K(. )

RegEx Demo

If \K is not available in your regex flavour then use:

#KODIPROP:inputstream\.adaptive\.license_key=.*\r?\n\K(. )

And use capture group #1 for your link.

RegEx Details:

  • #KODIPROP:inputstream\.adaptive\.license_key=: Match this prefix text literally
  • .*\r?\n: Match any text followed by line break
  • \K: Reset match info
  • (. ): Match 1 of any characters in capture group #1
  • Related