简体   繁体   English

如何使用RegEx在记事本中的两个单词之间添加“ _”

[英]How to use RegEx to add “_” between two words with notepad++

I want to use Notepadd++ replace option with regular expression to accomplish this: 我想使用Notepadd ++ replace选项和正则表达式来完成此任务:

From: IntegrationName
To: Integration_Name

How can do this ? 怎么办呢?

My RegEx to search is: .[AZ] this finds: "oN" But I don't know what to put in the replace box so it will only add "_" between the "o" and the "N"... 我要搜索的RegEx是: .[AZ]查找:“ oN”但是我不知道要在替换框中添加什么,因此它将仅在“ o”和“ N”之间添加“ _”。

Another solution using lookaround assertions would be: 使用环顾断言的另一种解决方案是:

(?<=[a-z])(?=[A-Z])

and replace with 并替换为

_

Note : The "Match case" option needs to be active, otherwise Notepad++ will find a match between every two letters. 注意 :“大小写匹配”选项必须处于活动状态,否则Notepad ++将在每两个字母之间找到一个匹配项。

This regex will find every position where a lowercase is on the left and an uppercase is on the right. 此正则表达式将找到在左侧小写字母在右侧大写字母的每个位置。

You can make use of capture groups. 您可以使用捕获组。 If I have to take your current attempt and edit it as little as possible, you would get: 如果我必须进行当前尝试并进行尽可能少的编辑,您将获得:

(.)([A-Z])

This will store the match of . 这将存储的匹配项. into $1 and the uppercase letter in $2 , thus, you can use the following in the replace entry box: 变成$1并把大写字母变成$1 $2 ,因此,您可以在replace输入框中使用以下命令:

$1_$2

I know you've accepted an answer , but when I ran it, I got From: _Integration_Name 我知道您已经接受了答案 ,但是当我运行它时,我得到了From: _Integration_Name

Here's my idea; 这是我的主意;

(:\s)(.{1})([a-z]*)([A-Z]{1})

And use the following replace 并使用以下替换

$1$2$3_$4

在此处输入图片说明

I finaly did it like this: 我最终做到了这一点:

Find: ([a-z])([A-Z])
Replace with: $1_$2

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM