I was hoping someone could review my regular expression to make sure that it's doing what I want it to do.
So here's what I'm after:
- Search for a word within a word boundary - so it can be a word on its own, or a word within another word
- Grab the preceding 30 characters (if preceding characters exist), but only if they do not contain the word I am searching for.
- Grab the next 30 characters (if they exist)
So if I were searching for "car" for 1, I have:
(\b\w*car\w*\b)
For 2, I have:
((?!\b\w*car\w*\b).{30}|.{0,30})
For 3, I have:
.{0,30}
All together:
((?!\b\w*car\w*\b).{30}|.{0,30})(\b\w*car\w*\b).{0,30}
Have I got it right, will this do what I'm after?