I want to match sentences (everything that is not just a long word) of a minimum length...doesn't mean that the length of the sentence has to be minimal but that the length of the sentence has to be equal or bigger than a $minimum_length.
Anyway, if a minimal match is what you want, it still can be done with a regexp (without embedded code!), though a complicated one:
sub make_re { my $len = shift; $len > 3 or die "len <= 3"; my $re = "\\b" . join('|', map("\\w(?:\\s[\\s\\w]{$_,}?", reverse 1 .. ( +$len - 3)), "\\w+\\s+") . (")" x ($len - 3)) . "\\w+"; warn "re: /$re/\n"; return qr/($re)/; } my $re = make_re(5); while(<DATA>) { print "$1\n" if $_ =~ $re; } __DATA__ foo foo foooooooo foooooooo fooo foo foo foo foo foo foo foooooooo foo foo foo f foo fo fo foo f fo foo f fo
In reply to Re^3: RE question: Sentence with a minimum length
by salva
in thread RE question: Sentence with a minimum length
by lima1
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |