我想匹配以下字符串中的数据:
24.Legacy.S01E08.720p.HDTV.x264-AVS [rarbg]
Colony.S02E09.720p.HDTV.x264舰队[rarbg]
以下测试几乎可行但需要一些调整:
kwi 02, 2017 8:06:25 PM org.hibernate.Version logVersion
INFO: HHH000412: Hibernate Core {5.2.6.Final}
kwi 02, 2017 8:06:25 PM org.hibernate.cfg.Environment <clinit>
INFO: HHH000206: hibernate.properties not found
kwi 02, 2017 8:06:25 PM org.hibernate.annotations.common.reflection.java.JavaReflectionManager <clinit>
INFO: HCANN000001: Hibernate Commons Annotations {5.0.1.Final}
kwi 02, 2017 8:06:25 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
WARN: HHH10001002: Using Hibernate built-in connection pool (not for production use!)
kwi 02, 2017 8:06:25 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH10001005: using driver [com.mysql.jdbc.Driver] at URL [jdbc:sqlserver://localhost:3306/Test]
kwi 02, 2017 8:06:25 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH10001001: Connection properties: {user=elop, password=****}
kwi 02, 2017 8:06:25 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH10001003: Autocommit mode: false
kwi 02, 2017 8:06:25 PM org.hibernate.engine.jdbc.connections.internal.PooledConnections <init>
INFO: HHH000115: Hibernate connection pool size: 20 (min=1)
kwi 02, 2017 8:06:26 PM org.hibernate.service.internal.AbstractServiceRegistryImpl stopService
INFO: HHH000369: Error stopping service [class org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl] : java.lang.NullPointerException
答案 0 :(得分:1)
你是如此接近,你只需要为后半部分的要求添加测试:
(.*?).S([0-9]+)E([0-9]+).(.*?)-(.*?)\[(.*?)\]
答案 1 :(得分:1)
您不需要/ s修饰符,它会扩展。匹配元字符和换行符。 我建议使用/ e修饰符也允许小写&#39; s01e14&#39; 别忘了逃避像这样的正则表达式。与 \。和\ [
// NAME SEASON EPISOE MEDIUM OPTIONS
$regex = '/(.+)\.S([0-9]+)E([0-9]+)\.(.+)\[(.+)\]/i';
preg_match_all(
$regex,
$download,
$posts,
PREG_SET_ORDER
);
用&#39; 24.Legacy.S01E08.720p.HDTV.x264-AVS测试[rarbg]&#39;
Array
(
[0] => 24.Legacy.S01E08.720p.HDTV.x264-AVS[rarbg]
[1] => 24.Legacy
[2] => 01
[3] => 08
[4] => 720p.HDTV.x264-AVS
[5] => rarbg
)
答案 2 :(得分:1)
然后写下来:)
^
(?P<title>.+?) # title
S(?P<season>\d+) # season
E(?P<episode>\d+)\. # episode
(?P<quality>[^-]+)- # quality
(?P<type>[^[]+) # type
\[
(?P<torrent>[^]]+) # rest
\]
$
答案 3 :(得分:0)
如果某个部分是可选的,只需在其周围添加一些( )
并在其后面添加?
,就像这样
// NAME SEASON EPISOE MEDIUM OPTIONS
$regex = '/(.+)\.S([0-9]+)E([0-9]+)\.(.+)(\[(.+)\])?/i';
但请注意更改$match
索引
Array
(
[0] => 24.Legacy.S01E08.720p.HDTV.x264-AVS[rarbg]
[1] => 24.Legacy
[2] => 01
[3] => 08
[4] => 720p.HDTV.x264-AVS
[5] => [rarbg]
[6] => rarbg
)
如果您不需要rarbg
值,则可以跳过内部()
// NAME SEASON EPISOE MEDIUM OPTIONS
$regex = '/(.+)\.S([0-9]+)E([0-9]+)\.(.+)(\[.+\])?/i';