Sequentially replace multiple places matching single pattern in a string with different replacements
问题 Using stringr package, it is easy to perform regex replacement in a vectorized manner. Question: How can I do the following: Replace every word in hello,world??your,make|[]world,hello,pos to different replacements, e.g. increasing numbers 1,2??3,4|[]5,6,7 Note that simple separators cannot be assumed, the practical use case is more complicated. stringr::str_replace_all does not seem to work because it str_replace_all(x, "(\\w+)", 1:7) produces a vector for each replacement applied to all