Won't this turn TRIM('OLD', 'DOLLMAN') into 'MAN'?  That is not mysql compatible. 
Fix and add test cases like TRIM('OLD', 'DOLLMAN'), TRIM('OLD', 'OGRE'), TRIM('OLD', 'OLDOGRE') (result matches just the start of the pattern), TRIM('OLD', 'DEVIL'), TRIM('OLD', 'OLDDEVIL') (result matches just the end of the pattern).