in reply to Find substring based on words and not in charachters
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Find substring based on words and not in charachters (Updated.)
by choroba (Cardinal) on Dec 02, 2014 at 17:16 UTC | |
by BrowserUk (Patriarch) on Dec 02, 2014 at 17:22 UTC | |
by GotToBTru (Prior) on Dec 02, 2014 at 20:40 UTC | |
|
Re^2: Find substring based on words and not in charachters (Updated.)
by Anonymous Monk on Dec 03, 2014 at 09:20 UTC |