s/ (?<= # Look back-group weak # Match the word weak # tag (?: # Non capturing group ){6} # There are 7 input tags, one already matches, so 6 to go. ) # End look-back (?= # Look-ahead-group strong ) # End look-ahead / the text you want to insert /ixg;