首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >在notepad++中搜索和替换多个单词

在notepad++中搜索和替换多个单词
EN

Stack Overflow用户
提问于 2012-07-09 13:23:23
回答 3查看 54K关注 0票数 31

有人知道如何在notepad++中一次替换几个不同的单词吗?

例如:

我有“好”,“好”和“好”,我想把它们同时替换成“坏”,“差”和“不”。

我知道我可以逐个替换它们,但我面临的问题需要我替换很多单词,这不方便做。

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2013-04-25 00:18:04

从插件管理器安装Python Script插件。

创建一个包含替换项的文件(例如,C:/Temp/Subsubtions.txt),用空格分隔值:

代码语言:javascript
复制
good bad
great worse
fine not

创建一个新脚本:

代码语言:javascript
复制
with open('C:/Temp/Substitutions.txt') as f:
    for l in f:
        s = l.split()
        editor.replace(s[0], s[1])

对要替换的文本运行新脚本。

票数 25
EN

Stack Overflow用户

发布于 2018-03-29 06:04:49

我四处寻找一些可以同时替换多个术语的软件,Notepad ++有字符限制(在替换字段中不能超过2046个字符),所以我决定用HTML制作我自己的替换版本,这是网站:

https://jsfiddle.net/Byte/y50q1e7g/

代码语言:javascript
复制
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]));
	}
	
}
代码语言:javascript
复制
*{
	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;
}
代码语言:javascript
复制
<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>

票数 6
EN

Stack Overflow用户

发布于 2016-01-06 06:30:52

如果您总是在几个不同的文件中替换相同的单词,使用these buttons记录一次操作并将其保存为宏将是很有帮助的。*Notepad++

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/11389466

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档