Quantcast
Viewing all articles
Browse latest Browse all 69261

Clone an array element a varying number of times

Hello,

 

I am trying to make a vi file that does the following:

1. It accepts a string as an input. The string contains a series of concatenated commands.

2. It finds a command of the type repeat 2 <xxx>

3. It replaces "repeat 2 <xxx>" with "xxx xxx" (e.g. repeat 3 <xxx> would become "xxx xxx xxx"). The markers < and > can be substituted with a different symbol (e.g. [], {}, ()).

4. This happens for all the instances of repeat commands within the string, so that in the end a new string is produced that does not contain any repeat commands.

Image may be NSFW.
Clik here to view.
repeat.png

I attach a screenshot of the program so far, as well as the program itself.

 

I cannot figure out how to use the regular expressions properly. "Repeat [0-9]" does not capture the entire command. I would like to have something like "Repeat [0-9] <*>" where * can be anything, but I cannot figure out how to write this using the regular expressions.

 

Also, is there an elegant way to do what I want using the search and replace string vi?

 

Any help would be greatly appreciated.


Viewing all articles
Browse latest Browse all 69261

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>