in reply to Regex explanation

Sure. It looks for the phrase 'lib' more than 1 character after a slash. If that is found then it replaces everything up to and including the 'lib' with what was between the slash and the character before the 'lib'. The expression to be matched against (and altered) is in $lib_name.

eg. if the expression were 'foo/barlib' the result would be 'ba'