正则表达式匹配模式和前缀

时间:2016-08-05 13:30:55

标签: php regex

我需要一个匹配日期的模式,我需要在日期之前的前缀

$prefix = '^(.*)';

preg_match("/$prefix(\d+) (may) (2016)/mi", $input, $matches)

输入1(工作)

3 may 2016
\\1 
\\2 3
\\3 may
\\4 2016

输入2(不工作)

17 may 2016
\\1 1
\\2 7
\\3 may
\\4 2016

输入3(不工作)

prefix 17 may 2016
\\1 prefix 1
\\2 7
\\3 may
\\4 2016

2 个答案:

答案 0 :(得分:2)

试试吧

org.elasticsearch.index.mapper.internal.SourceFieldMapper

或者如果您需要特定的可能和2016年

^(.*?)(\d+) (\w+) (\d+)$

答案 1 :(得分:2)

尝试这个,我认为,它可以工作:

$prefix = '^(.*?)';

preg_match("/$prefix(\d{1,2}) (\w{3,10}) (2016)/", $input, $matches);

Here you can test it.

相关问题