 <p>Maybe this one close to your expression will fit your need :</p> <p>just get rid of chars that your are not interested after your keyword or match the end of string</p> <blockquote> <p>(?:[a-zA-Z'-]+[^a-zA-Z'-]+){0,5}keyword(?:[^a-zA-Z'-]+|$)(?:[a-zA-Z'-]+[^a-zA-Z'-]*){0,5}</p> </blockquote>