Format string with regex in c#
c#, regex
Solution
Try `Regex.Replace(input, @"(\w{4})(\w{4})(\w{4})", @"$1-$2-$3");`
Regex is often derided, but is a pretty neat way of doing what you need. Can be extended to more complex requirements that are difficult to meet using string methods.
Problem
I would like to format a string that looks like this ``` BPT4SH9R0XJ6 ``` Into something that looks like this ``` BPT4-SH9R-0XJ6 ``` The string will always be a mix of 12 letters and numbers Any advice will be highly appreciated, thanks