regex - Match max 5 words before and after a certain word -
i need regex match @ 5 words before , after word. example:
the word "the"
the string "john ely gets start dodgers, while old friend takashi saito gets start brewers in bullpen game milwaukee."
there should 2 results:
john ely gets start the dodgers, while old friend takashi
takashi saito gets start the brewers in essentially
any ideas???
thanks
(?:[a-za-z'-]+[^a-za-z'-]+){0,5}the(?:[^a-za-z'-]+[a-za-z'-]+){0,5}
note regex engines won't deal overlapping matches.
Comments
Post a Comment