1

私はテキストを持っていますSummary for rxd7865 November 13, 2012 to November 13, 2012

November 13, 2012上記のテキストのような日付文字列のみを取得したい。

これを行うためにPHPで正規表現を使用するにはどうすればよいですか?

4

2 に答える 2

2

正規表現:

preg_match('/(?<the_date>(January|February|March) [0-9]{2}, 20[0-9]{2})/', $string, $matches);
echo $matches[the_date];

説明:

() // are called capture groups or matches
(?<name>) // are named capture groups or named matches
| // separator between a list of alternative matches
[] // is a character class
[0-9] // is a character class that allows only characters from 0 to 9
{} // is a repetition specifier
[]{2} // allows the character class to repeat twice
于 2013-01-22T10:26:54.913 に答える
0

preg_match_allでは、 PCRE 構文を使用します

于 2013-01-22T10:27:07.753 に答える