CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Regular Expressions: Re: [NuclearClam] matching sentences: Edit Log



NuclearClam
Novice

Aug 7, 2002, 4:44 PM


Views: 18103
Re: [NuclearClam] matching sentences

i found a semi-solution... it matches all of the criteria that i'm looking for, but... if there are multiple sentences like "La... No... Yes. What? Whee..." it'll count them all but *one* sentence ending in "..." It does it every time. As soon as there are two sentences like that, one gets left out. i don't understand it. anyway, here's my terrible, terrible net of regex's that i was at least competent enough to separate:

Code
  my $paragraph = q~ Who. Nine... What? How now?! "She." (She). No... Seven... Eight... ~;   

my $count = 0;

$ac = '(?:\w\.){2,}'; #acronyms
$endpunc = '[!?]+(?:[\'\"]{0,2})';
$other = '[^\w\s]';
$wword = '(?:(?:(?:$other+\w+)|(?:\w+$other+))?)'; expand($wword);
$words = '(?:\w+|$wword)?(\w+)?|(?:$ac)'; expand($words);
$sent = '(?:^|\W+)(?:(?:$words)(?:\s+)?)+(?:$endpunc)'; expand($sent);
sub expand ($) { $_[0] =~ s/\$(\w+)/${$1}/g; }
$count = $paragraph =~ s/$sent/$&/g;

print $count;


it sucks to almost have it done and get stuck on one, insignificant bug :\

btw, the expanded regex looks like this:

Code
  /\W+(?:(?:(?:\w+|(?:[^\w\s]+\w+(?:[^\w\s]+)?))?(\w+)?|(?:(?:\w\.){2,}))(?:\s+)?)+(?:[!?]+[\'\"]{0,2})/

Unimpressed


(This post was edited by NuclearClam on Aug 8, 2002, 8:02 PM)


Edit Log:
Post edited by NuclearClam (Novice) on Aug 7, 2002, 4:48 PM
Post edited by NuclearClam (Novice) on Aug 7, 2002, 4:49 PM
Post edited by NuclearClam (Novice) on Aug 7, 2002, 5:04 PM
Post edited by NuclearClam (Novice) on Aug 8, 2002, 8:02 PM


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives