1input 12345 2output gsub(/regex/,"x",input) 3 4regex output 5(^) x12345 6($) 12345x 7(^)|($) x12345x 8($)|(^) x12345x 9(2) 1x345 10(^)|2 x1x345 112|(^) x1x345 12($)|2 1x345x 132|($) 1x345x 14(2)|(^) x1x345 15(^)|(2) x1x345 16(2)|($) 1x345x 17($)|(2) 1x345x 18.((2)|(^)) x345 19.((^)|(2)) x345 20.((2)|($)) x34x 21.(($)|(2)) x34x 22x*((2)|(^)) x1x345 23x*((^)|(2)) x1x345 24x*((2)|($)) 1x345x 25x*(($)|(2)) 1x345x 26