Question: I am not using a coding language. This has to be straight regex. 

I need to add a variable length of whitespace between two strings. The string I am passing to the regex has the number of whitespaces in the string itself and will need to be replaced:

```
string1 *27* string2

```

so I need to insert 27 whitespaces into this string between string1 and string 2

```
\*(\d+)\*

```

This is my capture and it appear to be working, but I was trying to setup my replace with this:

```
\s{$1}

```

or this:

```
$&\s{$1}

```

So how would you do it? I am using expresso for my validation, but not all the regex patterns are supported by the text engine I am using.

Answer: 
This is not possible with straight regex. Regex would need some sort of parsing capabilities to use the captured variable and translate it into repeating spaces.

The way you want replace to work is not possible, also. As the replace portion of a regex is a straight text replace, and not another regex evaluator....it would be kind of cool to have some sort of recursive regex though :)
One way using a `perl` flavour regexp:

```
perl -e '
  $s = q[string1 *27* string2]; 
  $s =~ s/\s+\*(\d+)\*\s+/" " x $1/e; 
  print $s
'

```

Output:

```
string1                           string2

```