逐行增量替换文本(重新开始每行计数)。
我尝试了各种解决方案,例如Notepad ++列替换,TextPad增量替换和此处Notepad++ incrementally replace所列的Python脚本,但没有按我想要的方式工作(它们不会替换成一行,也不会从每一行重新启动)。
我可以替换为查找文本,但不知道如何增加它。
FIND: (\[2s\])
REPLACE: <br /><b class="num">\1</b>
所以我想要这个:
test text various [2s] tes text various [2s] tes text various [2s] to replace w abc-mine1.txt , [2s] to replace w abc-mine1.txt , [2s] to replace w abc-mine1.txt , [2s] to replace w
test text various [2s] tes text various [2s] tes text various [2s]
test text various [2s]
成为这个
test text various <br /><b class="num">1</b> tes text various <br /><b class="num">2</b> tes text various <br /><b class="num">3</b> to replace w abc-mine1.txt , <br /><b class="num">4</b>] to replace w abc-mine1.txt , <br /><b class="num">5</b> to replace w abc-mine1.txt , <br /><b class="num">6</b> to replace w
test text various <br /><b class="num">1</b> tes text various <br /><b class="num">2</b> tes text various <br /><b class="num">3</b>
test text various <br /><b class="num">1</b>
答案 0 :(得分:1)
我认为您无法使用普通的正则表达式查找和替换来做到这一点。
但是,如果您可以安装 Python脚本插件,那么以下代码应该可以解决问题:
repstr = "[2s]"
lcount = editor.getLineCount()
newstr = ""
i = 0
while i < lcount:
actline = editor.getLine(i)
counter = 1
while actline.find(repstr) > 0:
actline = actline.replace(repstr, "<br /><b class=\"num\">"+str(counter)+"</b>",1)
counter += 1
newstr = newstr + actline
i += 1
editor.clearAll();
editor.appendText(newstr);