我有一些网址,如:
http://exmple.com/subtitles/my-subtitle-name-3
http://exmple.com/subtitles/my-subtitle-name-3/arabic
http://exmple.com/subtitles/my-subtitle-name-3/danish
http://exmple.com/subtitles/my-subtitle-name-3/farsi_persian
http://exmple.com/subtitles/my-subtitle-name-3?wdwrf
http://exmple.com/subtitles/my-subtitle-name-3?wdwrf=ok&nep=1
http://exmple.com/subtitles/my-subtitle-name-3/arabic/
http://exmple.com/subtitles/my-subtitle-name-3/danish/
http://exmple.com/subtitles/my-subtitle-name-3/farsi_persian/
http://exmple.com/subtitles/my-subtitle-name-3/farsi_persian/?sdsf
http://exmple.com/subtitles/my-subtitle-name-3/farsi_persian/?sdsf&dfe=pl
http://exmple.com/subtitles/my-subtitle-name-3/arabic/1627077
http://exmple.com/subtitles/my-subtitle-name-3/danish/1629022
http://exmple.com/subtitles/my-subtitle-name-3/farsi_persian/1593665
http://exmple.com/subtitles/my-subtitle-name-3/arabic/1627077/
http://exmple.com/subtitles/my-subtitle-name-3/danish/1629022//
http://exmple.com/subtitles/my-subtitle-name-3/farsi_persian/1593665/?1xds我正在尝试获取字幕名,在本例中是它的my-subtitle-name-3,因此它应该在所有上述urls中捕获my-subtitle-name-3。
它尝试了这个regex \/subtitles\/(.*?)\/.*,这样它就不匹配在URL上没有任何附加/的URL,
我厌倦了让/在我的正则表达式上是可选的,所以我也使用了\/subtitles\/(.*?)\/?.*,但是它根本不起作用
下面是测试链接:
https://regex101.com/r/BOIfzG/1
https://regex101.com/r/BOIfzG/2 ==>在使用非贪婪之后,我尝试使\成为可选的,但它没有工作。
第一个检测到大多数的URL,第二个不工作。
发布于 2017-09-21 23:51:45
https://stackoverflow.com/questions/46354771
复制相似问题