PHP regex to match sentences that contain a year
Posted
by zen
on Stack Overflow
See other posts from Stack Overflow
or by zen
Published on 2010-03-23T22:53:09Z
Indexed on
2010/03/23
23:03 UTC
Read the original article
Hit count: 554
I need a regular expression that will extract sentences from text that contain a year in them.
Example text:
Next, in 1988 the Bradys were back again for a holiday celebration, "A Very Brady Christmas". Susan Olsen (Cindy) would be missing from this reunion, Jennifer Runyon took her place. This was a two hour movie in which the Bradys got together to celebrate Christmas, introducing the world to the spouses and children of the Brady kids. This movie was the highest rated TV-movie of 1988.
If the example text was variable $string, I need it to return:
- $sentenceWithYear[0] = Next, in 1988 the Bradys were back again for a holiday celebration, "A Very Brady Christmas".
- $sentenceWithYear[1] = This movie was the highest rated TV-movie of 1988.
If it's possible to retain the year via regex, I'd use the year within the sentence and eventually insert the sentences into a database like:
INSERT INTO table_name (year, sentence) VALUES ('$year', '$sentenceWithYear[x]')
© Stack Overflow or respective owner