Hello,
I'm looking for a pattern which finds a word in a text and returns the word and 50 words before and 50 words after the found word.
Finding 50 characters before and after is no problem:
"|(.{50})".$strWord."(.{50})|is"
Thanks!
RegExp: 50 words before and 50 words after a match
Moderator: General Moderators
-
visionmaster
- Forum Contributor
- Posts: 139
- Joined: Wed Jul 14, 2004 4:06 am
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
Not tested...
Add as many punctuation marks into the square brackets as you may find stuck to the end of a word...
EDIT: This is better
It'll find anything that isn't whitespace up until a space or tab or newline etc 50 times before the word and 50 times after (case insensitive)
Code: Select all
I removed this regexp cos it was useless ;-)EDIT: This is better
Code: Select all
'/(ї\S]{50}\s'.$word.'\sї\S]{50})/i'- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia