Atom编辑器:RegEx替换为大写/小写 [英] Atom Editor: RegEx replace to uppercase/lowercase

查看:239
本文介绍了Atom编辑器:RegEx替换为大写/小写的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在Atom编辑器中将字符串中的某些字符替换为大写/小写字母.

I'm trying to replace some characters in a string with their uppercase/lowercase equivalents in Atom Editor.

假设我有以下字符串:

some:test:sequence

并希望得到结果:

Some:Test:Sequence

我知道\u$1\l$1之类的东西,但是它们在Atom中不起作用,因为Atom使用的是JS样式的RegEx.但是,我发现的JS-RegEx解决方案始终涉及调用一个函数(请参见此处的示例),而这在以下情况中是不可能的:原子,afaik.

I’m aware of things like \u$1 and \l$1, but they do not work in Atom, as Atom is using JS-style RegEx. The JS-RegEx solutions I found, however, always involve calling a function (see example here), which is not possible in Atom, afaik.

有人知道是否有办法实现这一目标吗?我也不介意为更强大的正则表达式搜索/替换安装程序包,但还没有找到一个程序包,我想避免为此独自编写一个程序包.

Does anyone know if there is a way to achieve this? I also don’t mind installing a package for a more powerful regex search/replace, but haven’t found one and I’d like to avoid writing one on my own just for this.

请注意:我不是在寻找用于查找/选择字符的解决方案.选择的效果很好,并且比示例中的要复杂一些.

Please note: I’m not looking for a solution to find/select the characters. The selection works just fine and is a bit more complex as in the example.

推荐答案

请注意,尽管您说的是问题与选择无关,但我使用的是更简化的示例.

Note that whilst you said the question is not about the selection, I'm using a more simplified example.

如果您的字符串包含:This is a Mixed case String! I want every Letter to Start with A Capital.

If you have a string consisting of: This is a Mixed case String! I want every Letter to Start with A Capital.

您可以使用\b\w的Regex选择器来查找字符串中每个单词的开头字符. (通过Cmd + F完成,然后单击右侧菜单上的.*进行正则表达式搜索)

You can use the Regex selector of \b\w to find the first characters of every word in the string. (Done by Cmd + F and clicking .* on the right hand menu for Regex search)

现在按Alt + Enter选择所有找到的结果,这将突出显示Regex查询的所有结果.之后,要使每个第一个字母都变为大写字母,可以按Cmd + K -> Cmd + U键,您可以根据需要在此处进行修改.

Now press Alt + Enter to select all of the found results, this should highlight all results of the Regex query. Following this, to make every first letter uppercase you can press Cmd + K -> Cmd + U, you can modify them however you want from here.

景气!现在,该字符串应如下所示:This Is A Mixed Case String! I Want Every Letter To Start With A Capital.

Boom! The string should now look like: This Is A Mixed Case String! I Want Every Letter To Start With A Capital.

一段时间以来,我一直在寻找这个问题的答案,这是我的答案来源:

I've been looking for an answer for this question for a while, here are my sources for the answer:

johno关于如何从Regex搜索中选择所有结果的答案(答案中包括相关的提取请求)

这篇关于Atom编辑器:RegEx替换为大写/小写的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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