Page 1 of 1

regex - word in sentence

Posted: Tue Jul 06, 2010 6:21 pm
by kidot
Hi

I am quite new to regex and am looking all day long for a solution (my eyes are burning already :-) )

I have lets say three sentences:

this is a text with my specific word! What if the word is in? No Text found here.

I need the complete sentence where i.e. the word "text" (not case sensitive) is found.

So in this case the match would be
this is a text with my specific word! No Text found here.

But I have no clue and I tried a lot - I tried that much that I lost the line... I assume that this is easy for pros, but I am just in the beginning and regex is "difficult" ...

Can someone help me please.
Regards
KI

Re: regex - word in sentence

Posted: Wed Jul 07, 2010 10:05 am
by kidot
Hi again,

I am struggeling - but I found a snippet that can identify sentences (hopefully in a good way)

(?s-i)(?<=^|\A|\.[^.]+)[A-Z\d]
(
(Jan|Feb)\.\s+\d{1,2}\s*,\s+\d{4}
|
[^!?]
)*?
[.!?]
(?=\s|$|\Z)



Now I need your help please.

I want to search for a specific words like (air|rain|sun) but I do not know where to put this and how.
Can someone help me please?

Thanks
Ki

Re: regex - word in sentence

Posted: Wed Jul 07, 2010 2:21 pm
by kidot
Hi all
please help me with this task.

I have another approach :

([^\\.\\?\\!])
*
(air|energy|water)
[^\\.\\?\\!]
*
([!?.:])

But the thing that is missing is that I need to capture the whole sentence. What am I missing.
Thanks
Ki