如何在字符串的特定位置添加字符? [英] How do I add a character at a specific position in a string?
本文介绍了如何在字符串的特定位置添加字符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用 Notepad++ 并且想使用正则表达式替换在字符串中的特定位置插入一个字符.
I am using Notepad++ and want to insert a character at a specific position in a string using regular expression replacement.
例如,在每行的第 6 位插入逗号的表达式是什么?
What would the expressions be to, say, insert a comma at position 6 of every row?
推荐答案
如果要在第六个字符后添加一个字符,简单使用搜索
If you want to add a character after the sixth character, simple use the search
^(.{6})
和替换
$1,
(例如插入一个,
)
从技术上讲,这会将每行的前 6 个字符替换为 MatchGroup 1(反向引用 $1
),后跟一个逗号.
technically spoken this will replace the first 6 characters of every line with MatchGroup 1 (backreference $1
) followed by a comma.
这篇关于如何在字符串的特定位置添加字符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文