Adding a space variable between two lines

I do not use coding language. It must be a direct regex.

I need to add a variable length of spaces between two lines. The line that I pass to the regular expression has the number of spaces in the line itself and needs to be replaced:

string1 *27* string2

so i need to insert 27 spaces in this line between line 1 and line 2

\*(\d+)\*

This is my capture and seems to work, but I was trying to set up my replacement as follows:

\s{$1}

or that:

$&\s{$1}

So how would you do that? I use expresso for my validation, but not all regular expression patterns are supported by the text engine that I use.

+3
source share
2 answers

. Regex - .

, , . , ... - :)

+1

regexp perl:

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

:

string1                           string2
0

All Articles