我对regex不太了解。需要帮助!
我有下面的rtsp,需要将它分开
rtsp://user:password@google.com:554/ISAPI/streaming/channels/102和下面的正则表达式
(rtsp):\/\/(?:([^\s^@\/]+?)[@])?([^\s\/:]+)(?:[:]([0-9]+))?([/\s(.*)])结果为101 Result
Full match rtsp://user:password@google.com:554/
Group 1. rtsp
Group 2. user:password
Group 3. google.com
Group 4. 554
Group 5. / 发布于 2020-08-04 18:58:23
它的用户名组2:pasword不能是空的,您可以省略它周围的可选非捕获组(?:...)?。
否定字符类不必是非贪婪的[^\s@/]+,因为它不能传递@字符。(请注意,[^\s^@\/]也不允许与^和/匹配)
如果您想匹配第5组中的"rest“,则可以匹配/,后面是任何字符0+倍(\/.*)
您不必在@和:中使用方括号
(rtsp):\/\/([^\s@/]+)@([^\s/:]+)(?::([0-9]+))?(\/.*)https://stackoverflow.com/questions/63253134
复制相似问题