View Single Post
Old 01-31-2013, 04:41 PM   PM User | #1
xelawho
Senior Coder

 
xelawho's Avatar
 
Join Date: Nov 2010
Posts: 2,437
Thanks: 52
Thanked 453 Times in 451 Posts
xelawho will become famous soon enoughxelawho will become famous soon enough
another regex question

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.

Any suggestions?

Last edited by xelawho; 01-31-2013 at 04:50 PM.. Reason: clarifying
xelawho is offline   Reply With Quote