Regex 101 Discussion I8 – replace space count with spaces

Exercise I8 – replace space count with spaces

Given a string with embedded space counts:

<15sp>Indented by 15 spaces

Replace the <<count>sp> with <count> spaces.

So, if you have


you should end up with



This is fairly straightforward. First, we need to match the space count “thingy”. We’ll use:


And then we’ll use a MatchEvaluator to do the replacement.

static public string Evaluator(Match match)

   int count = Int32.Parse(match.Groups[“Count”].Value); 
   return new String(‘ ‘, count);

Comments (1)

  1. typo… <?<Count>d+)sp> should be <(?<Count>d+)sp>