I am slowly getting my head around regex, but really it is mostly a mystery to me.
Here's the thing: I have a string (although I have no idea how that string will look). All I know is that the string will contain a word (I don't know what that word is either). I don't know if the string will be a paragraph, a sentence or a sentence fragment (the sentence may be cut off, either at the start or the end).
But I need to get as much of the sentence containing the word as possible, without getting too much.
So I figure that these are the "rules":
- Start capturing from the closest word before the variable word that starts with a capital/uppercase.
- If there is no word that starts with a capital before the variable word, start capturing from the start of the string.
- Equally, if the part of the string after the variable word contains a full stop/period, finish capturing at the full stop.
- If not, capture until the end of the string.
I know it's not perfect logic, but it doesn't have to be - all I want to do is to be able to show the word in some sort of context, like Word does when you do spellcheck.