从文本中检索特定 url 的正则表达式

regex to retrieve specific url from text

一个API我用returns这段文字:

<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"

我正在尝试检索第一个 URL,然后是 ; rel="h264-session-sdp

所以在这种情况下会是:http://192.168.1.10:8080/realLongUrl

我一直在摆弄尝试修改在 SO 上找到的示例,但似乎做对了。

选择大于和小于字符之间的文本:

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

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

如果您想 select 多行网址,请添加 g 和 m 修饰符:

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

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

试试这个/([^<]+)(?:>; rel\=\"h264\-session\-sdp\")/

试试这个:

/(?<=\<)(.*?)(?=\>)>; rel="h264-session-sdp"/