Modified the return value for extendMatch to handle returning the extension in either forward or reverse direction