基于正则表达式的匹配和替换与纳米? [英] Regex-based matching and sustitution with nano?

查看:21
本文介绍了基于正则表达式的匹配和替换与纳米?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道 nano 的搜索和替换功能,但它是否能够使用正则表达式进行匹配和替换(特别是使用匹配的一部分的替换)?如果是这样,您能否提供一些使用的语法示例(用于匹配和替换)?

I am aware of nano's search and replace functionality, but is it capable of using regular expressions for matching and substitution (particularly substitutions that use a part of the match)? If so, can you provide some examples of the syntax used (both for matching and replacing)?

我开始学习 Perl 风格的正则表达式,但我发现文本编辑器有时会提出自己的语法.

I cut my teeth on Perl-style regular expressions, but I've found that text editors will sometimes come up with their own syntax.

推荐答案

您需要在全局 nanorc 文件中添加或取消注释以下条目(在我的机器上,它是 <代码>/etc/nanorc):

You need to add, or un-comment, the following entry in your global nanorc file (on my machine, it was /etc/nanorc):

set regexp

然后启动一个新终端并按 CTRL + / 并进行替换,现在应该可以识别正则表达式.

Then fire up a new terminal and press CTRL + / and do your replacements which should now be regex-aware.

搜索conf->(S+):

替换为1_conf

a 替换所有出现的:

Press a to replace all occurrences:

最终结果:

这篇关于基于正则表达式的匹配和替换与纳米?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆