How to parse/extract/format a string based a pattern?

Databrickguy
New Contributor II

How to parse, extract or form a string based on a pattern?

SQL server has a function which will format the string based on a pattern. example,

a string is "abcdefgh", the pattern is XX-XX-XXXX,

the the string will be "ab-cd-efgh".

How to archive this with a function?