I am using Notepad++ and want to insert a character at a specific position in a string using regular expression replacement.
What would the expressions be to, say, i
If you want to add a character after the sixth character, simple use the search
^(.{6})
and the replacement
$1,
(Example inserts a ,
)
technically spoken this will replace the first 6 characters of every line with MatchGroup 1 (backreference $1
) followed by a comma.
Also using Vanilla Javascript
var str = 'USDYEN'
// add a / in between currencies
// var newStr = str.slice(0, 3) + ' / ' + str.slice(3)
// var newStr = str.slice(3) // removes the first 3 chars
// var newStr = str.slice(0,3) // removes the last 3 chars
var newStr = str.slice(0,3) + ' / ' + str.slice(3) // removes the first 3 and adds the last 3
console.log(newStr)
More information how to use slice()
https://www.w3schools.com/jsref/jsref_slice_string.asp