如何替换凯特正则表达式 [英] How to replace Kate regular expression

查看:150
本文介绍了如何替换凯特正则表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Kate编辑器.这是一个显示我的问题的最小示例:

I am using the Kate editor. Here is a minimal example that shows my problem:

我有一个文件,其中经常出现以下情况:

I have a file with a bunch of occurrences of:

\command{stuff}

其中,东西是任意的字母字符串.我要替换为

where stuff is some arbitrary string of letters. I want to replace this with

\disobey{stuff}

内容保持不变.正则表达式:

where stuff is unchanged. The regular expression:

\\command\{[a-zA-Z]*\}

匹配这样的表达式.因此,我用CTRL-r拉出了替换对话框,然后输入

matches such expressions. So I pull the replace dialog with CTRL-r, and enter

Find: \\command\{[a-zA-Z]*\}
Replace: \\disobey\{\1\}

因此在文档中,有一个实际实例,

So in the document, an actual instance is say,

\command{exchange}

当我按下替换"按钮时,将其更改为

and when I hit the replace button is changed to

\disobey{1}

在Kate文档中:附录B:正则表达式\ 1应该与使用的第一个模式匹配.这确实是正确的语法吗?我还尝试了$ 1,#1和其他各种功能.

In the Kate documentation: Appendix B: Regular Expressions, \1 should match the first pattern used. Is this indeed the correct syntax? I have also tried $1, #1, and various other things.

推荐答案

( )包裹值以将其捕获为一个组,以便可以在替换中使用它

Wrap the value with ( ) to capture it as a group, so you can use it in your replace

因此,像这样更改找到的正则表达式:

So change your find regex like this:

\\command\{([a-zA-Z]*)\}

您应该做的很好.

这篇关于如何替换凯特正则表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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