Perhaps seeeing exactly what is being matched and captured will help (/x regex modifier used to help my poor eyes):
>perl -wMstrict -le "my $s = qq{abandon/to\t(a road)\t}; $s =~ s{ ([^\t]*) \t ([^\t]*) \1 ([^\t]*) \t }{\t$2$1$3\t}xms; print qq{1 '$1' 2 '$2' 3 '$3'}; print qq{'$s'}; " 1 'o' 2 '(a r' 3 'ad)' 'abandon/t (a road) '
Update: This may help (note anchor at start of string): If the entire content of the first cell is repeated anywhere in the second cell, delete the entire content of the first cell:
>perl -wMstrict -le "for my $s (qq{abandon/to\t(a road)\t}, qq{abandon/to\txxx abandon/to yyy \t}, ) { print qq{'$s'}; (my $t = $s) =~ s{ \A ([^\t]+) (\t [^\t]* \1 [^\t]* \t) }{$2}xms; print qq{1 '$1' 2 '$2'} if defined($1) and defined($2); print qq{'$t' \n}; } " 'abandon/to (a road) ' 'abandon/to (a road) ' 'abandon/to xxx abandon/to yyy ' 1 'abandon/to' 2 ' xxx abandon/to yyy ' ' xxx abandon/to yyy '
And this, capturing less, may be slightly better:
s{ \A ([^\t]+) (?= \t [^\t]* \1 [^\t]* \t) }{}xms;
In reply to Re: Regex search and replace appears to be broken
by AnomalousMonk
in thread Regex search and replace appears to be broken
by elef
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |