有人知道如何在notepad++中一次替换几个不同的单词吗?
例如:
我有“好”,“好”和“好”,我想把它们同时替换成“坏”,“差”和“不”。
我知道我可以逐个替换它们,但我面临的问题需要我替换很多单词,这不方便做。
发布于 2013-04-25 00:18:04
从插件管理器安装Python Script插件。
创建一个包含替换项的文件(例如,C:/Temp/Subsubtions.txt),用空格分隔值:
good bad
great worse
fine not
创建一个新脚本:
with open('C:/Temp/Substitutions.txt') as f:
for l in f:
s = l.split()
editor.replace(s[0], s[1])
对要替换的文本运行新脚本。
发布于 2018-03-29 06:04:49
我四处寻找一些可以同时替换多个术语的软件,Notepad ++有字符限制(在替换字段中不能超过2046个字符),所以我决定用HTML制作我自己的替换版本,这是网站:
https://jsfiddle.net/Byte/y50q1e7g/
window.onload = function(){
$("textarea,input[type='text']").focus(function() { $(this).select(); } );
}
function replace(){
// Get Configuration
let separatedBy = new RegExp( $("#separatedBy").val() );
let useRegex = $("#useRegex").prop("checked");
let isCaseSensitive = $("#caseSensitive").prop("checked") ? "" : "i";
// Get 'Find' and 'Replace'
let find = $('#find').val().split(separatedBy);
let replace = $('#replace').val().split(separatedBy);
// Make result equal origin
$("#result").val($("#original").val());
// Run in each 'find' item
for(i=0; i<find.length; i++){
// check if not use Regex to escape the regex
find[i] = useRegex ? find[i] : find[i].replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&');
// Replace
$("#result").val($("#result").val().replace(new RegExp(find[i],"g"+isCaseSensitive), replace[i]));
}
}
*{
font-family: Sans-Serif;
box-sizing: border-box;
}
body{
padding:1em 10%;
}
textarea,input[type='text']{
font-family: monospace;
}
textarea{
border-radius: 5px;
width: 100%;
padding:1em;
}
.config{
width: 100%;
border-radius: 5px;
border: 1px solid #888888;
padding: 1em;
display: inline-block;
color: #888888;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<p>
Original text:<br />
<textarea id="original" rows="4" cols="50"></textarea>
</p>
<p>
Items to find:<br />
<textarea id="find" rows="4" cols="50">item1
item2
item3</textarea>
</p>
<p>
Items to replace:<br />
<textarea id="replace" rows="4" cols="50">replace1
replace2
replace3</textarea>
</p>
<p class="config">
<b>Configuration:</b><br><br />
- Items separated by <input id="separatedBy" type="text" value="\n" size="3" /> (Regex)<br />
- <input id="useRegex" type="checkbox"/> Use Regex in each item<br>
- <input id="caseSensitive" type="checkbox" checked/> Use case sensitive
</p>
<p>
<input type="button" value="Replace" onclick="replace()" />
</p>
<p>
Result:<br>
<textarea id="result" rows="4" cols="50"></textarea>
</p>
发布于 2016-01-06 06:30:52
如果您总是在几个不同的文件中替换相同的单词,使用these buttons记录一次操作并将其保存为宏将是很有帮助的。*Notepad++
https://stackoverflow.com/questions/11389466
复制相似问题