Update: Added minor optimisation. Update2: Rolled the optimisation into the while loop.
Something like this?:
#! perl -slw use strict; my $seg1 = "The man who likes reading books and writing poems."; my $seg2 = "The man who likes reading big books and poems."; my $best = ''; while( length( $seg1 ) > length( $best ) ) { while( $seg1 =~ m[(?!\s)(?=(\b.+\b)(?!\s))]g ) { my $bit = $1; $best = $bit if $seg2 =~ m[\Q$bit] and length( $bit ) > length +( $best ); } $seg1 =~ s[(?:\s|^)\S+$][]; } print $best; __END__ [17:04:21.46] C:\test>junk39 The man who likes reading
In reply to Re: Find substring based on words and not in charachters (Updated.)
by BrowserUk
in thread Find substring based on words and not in charachters
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |