1

An API I use returns this text:

<http://192.168.1.10:8080/longUrl>; rel="recording-session",
<http://192.168.1.10:8080/realLongUrl>; rel="h264-session-sdp", 
<http://192.168.1.10:8080/realLongDifferentUrl>; rel="h264-session-sdp", 
<rtp://239.1.1.18:5006>; rel="destination-high", 
<rtp://239.1.1.17:5006>; rel="destination-low"

I'm trying to retrieve the first URL that is followed by ; rel="h264-session-sdp.

So in this case that would be: http://192.168.1.10:8080/realLongUrl

I've been fiddling around trying to modify examples found here on SO, but just can's seem to get it right.

Audwin Oyong
  • 2,247
  • 3
  • 15
  • 32
JasperZelf
  • 2,731
  • 1
  • 22
  • 34
  • 2
    Can you show some of the fiddled regex that didn't work. – bobble bubble Nov 13 '15 at 16:52
  • Mainly been trying to modify the regex example found here: http://stackoverflow.com/a/413165/1577926. Replacing the curly brackets with my own delimiters. I keep getting the delimiters in the match as well as the content. – JasperZelf Nov 13 '15 at 16:55

3 Answers3

2

try this one /([^<]+)(?:>; rel\=\"h264\-session\-sdp\")/

Andrew Evt
  • 3,613
  • 1
  • 19
  • 35
0

Selects the text inbetween the greater then and less then characters:

?<=\<)(.*?)(?=>)

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

And if you wanted to select the urls on multiple lines, add the g and m modifiers:

/(?<=\<)(.*?)(?=>)/gm

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

Keith M
  • 1,199
  • 2
  • 18
  • 38
  • Tried to modify it to only the one I need, but it says it's invalid.... SyntaxError: invalid regexp group `var res = linkHeaders.match( /(?<=\<)(.*?)(?=\>)>; rel=\"h264-session-sdp\"/ );` – JasperZelf Nov 13 '15 at 17:15
  • try `var res = linkHeaders.match( /(?<=\<)(.*?)(?=\>)>; rel=\"h264-session-sdp\");` note the removed ending slash – Keith M Nov 13 '15 at 17:18
0

Try this:

/(?<=\<)(.*?)(?=\>)>; rel="h264-session-sdp"/
Ikbel
  • 7,721
  • 3
  • 34
  • 45