私はテキストを持っていますSummary for rxd7865 November 13, 2012 to November 13, 2012
。
November 13, 2012
上記のテキストのような日付文字列のみを取得したい。
これを行うためにPHPで正規表現を使用するにはどうすればよいですか?
正規表現:
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
preg_match_allでは、 PCRE 構文を使用します