regex

C

clsnyder

Hi,

I am trying to use regex to search a text file for certain word(s), and
if the word is found, extract every sentence which contains it as an
output text file. Any help would be appreciated.
 
B

Brian Wakem

Hi,

I am trying to use regex to search a text file for certain word(s), and
if the word is found, extract every sentence which contains it as an
output text file. Any help would be appreciated.


In what way does your solution fail? We can't help you if we don't know
what you have done.
 
M

Mark Seger

I am trying to use regex to search a text file for certain word(s), and
if the word is found, extract every sentence which contains it as an
output text file. Any help would be appreciated.

I'd think the biggest problem here is to define what a sentence is. It
just can't be a string of words that end in '.' since abbreviations do
as well.
-mark
 
A

Arne Ruhnau

Mark said:
I'd think the biggest problem here is to define what a sentence is. It
just can't be a string of words that end in '.' since abbreviations do
as well.

Finding sentence delimiters / abbreviations is usually done with a list of
known abbreviations, but there are also approaches that test if a dot and
its preceeding word form a collocation, thus are dependent and can be
treated as an abbreviation...
But still, you can have abbreviations at the end of a sentence and thus
have an ambiguous dot...

If the OP does not need to do serious natural language processing, he/she
can nevertheless use a rather naive definition of "sentence".

Arne Ruhnau

PS: If thats not enough, you may start to wonder whether "The White House"
should not form a word...
 
T

thundergnat

Hi,

I am trying to use regex to search a text file for certain word(s), and
if the word is found, extract every sentence which contains it as an
output text file. Any help would be appreciated.

The hardest part of that will be determining what constitutes a sentence.
Rather than trying to roll your own, take a look at Lingua::En::Sentence.
It isn't perfect, but it is probably as good or better than you could do
yourself.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,152
Latest member
LorettaGur
Top