in reply to Matching bits of 2 strings
When run it generates the following output#! /usr/local/bin/perl $string1 = "the date is today"; $string2 = "the date is tomorrow"; $concat = $string1 . "#" . $string2; if ( $concat =~ m/^(.*)(.*)#\1(.*)$/ ) { print "matching part: $1\n"; print "difference: $2\ndifference: $3\n"; } else { print "strings $string1 and $string2 do not match!\n"; }
I have to note that this solutions uses the fact dat the to strings doesn't contain any poundsymbols (#). When one of the to strings contain a poundsymbol, you have to use another symbol(sequence) to, for example:matching part: the date is to difference: day difference: morrow
I hope that this will give you a hint to construct your own solution!... $concat = $string1 . "#!!#" . $string2; if ( $concat =~ m/^(.*)(.*)#!!#\1(.*)$/ ) { ...
|
|---|