Concatenate Strings with Context
Haskell, 184 182 201 199 155
s&amp;t|(a,'|':b)&lt;-f t,(x,'|':y)&lt;-f$r s,x#b,a#y=r(y!r a)++b!r x|0&lt;1=&quot;&quot;
r=reverse
a!b=a++drop(length a-1)b
(#)a=and.zipWith(==)(r a).filter h
f=span h
h=(/='|')

example run:
&quot;|a|&quot;&amp;&quot;|b|&quot; -- returns &quot;|ab|&quot;
&quot;|a|x&quot;&amp;&quot;|b|&quot; -- returns &quot;&quot;

if there isn't a match an empty string will be returned. otherwise the result would be returned.
partial explanation:
# is a function which gets two strings, and returns whether or not they match.
! gets two strings and returns the first one concatenated with extra character from the second (if there are any).
the main function &amp; uses span (/='|') to split the inputs into two parts, a|b|c to a, b|c, checks if the contexts match, and then uses ! twice to assemble the output.
Edit: mage-late regolfing seems to be pretty effective.