Php 加入几个正则表达式模式(不是一些str、任何单词、日期)
我有三种有效的正则表达式模式:Php 加入几个正则表达式模式(不是一些str、任何单词、日期),php,regex,Php,Regex,我有三种有效的正则表达式模式: ^(sezon\s[0-9]+) => finds if string starts with sezon $$ where $is digit ([a-zA-z]*|\b)*.* => that should match any words \d{1,2}[.]\d{1,2}[.]\d{2,4} => that matches date 现在我想否定第一个和第三个模式,把它们加入第二个模式 Sezon 2 some text here 0
^(sezon\s[0-9]+) => finds if string starts with sezon $$ where $is digit
([a-zA-z]*|\b)*.* => that should match any words
\d{1,2}[.]\d{1,2}[.]\d{2,4} => that matches date
现在我想否定第一个和第三个模式,把它们加入第二个模式
Sezon 2 some text here 03.02.1203 => should be excluded
Sezon more text => included
Sezon 2 mote set amet => excluded
some date here 20.20.2222 =>excluded
only text here also => included
2 - => excluded
我试图实现的是通过以下方式拒绝字符串:
- 最后的日期,
- 一开始是Sezon$
- 一开始
1 -
Pilot (pilot)
26.10.2015
2 -
Stronger Together
2.11.2015
3 -
Fight or Flight
9.11.2015
线被分解函数打断。
对于每一行字符串,我想检查它的季节、编号、标题或日期,然后在每种情况下执行不同的操作。使用:
见
详细信息:
-字符串的开头^
-如果字符串以0+水平空格、1+数字、0+空格和(?!\h*\d+\h*-|sezon\h+[0-9]+|.*\d{1,2}[.]\d{1,2}[.]\d{2,4}$)
开头,则会导致匹配失败的负前瞻(请参见-
)或以\h*\d+\h)*-
开头,1+空格和1+数字,或(sezon
)以
模式结尾(因为它后面必须有字符串结尾-\d{1,2}[.]\d{1,2}[.]\d{2,4}
)$
-除换行符以外的1个或多个字符+
*
。它应该匹配其他内容之间的任何文本字符串。这就是为什么我想把三种模式合并成一个更新的问题。在我测试之前,还有一件事发生了,这是否意味着您有一个包含多个换行符和要提取的记录的字符串?几乎。还有一个例外:那些“1-”的。任何空格字符OK,请尝试^(?!sezon\s+[0-9]+|.*\d{1,2}[.]\d{1,2}[.]\d{2,4}$\h*\d+\h*-).+
,请参见“是”,这样做。我以为加上^会否定,但我错了。请更新您的原始答案,以便我可以接受。谢谢
'~^(?!\h*\d+\h*-|sezon\h+[0-9]+|.*\d{1,2}[.]\d{1,2}[.]\d{2,4}$).+~im'