正则表达式在PhpStorm/Webstorm(Intellij-IDEA)中用小写字母替换大写 [英] Regex replace uppercase with lowercase letters in PhpStorm/Webstorm (Intellij-IDEA)

查看:545
本文介绍了正则表达式在PhpStorm/Webstorm(Intellij-IDEA)中用小写字母替换大写的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿,我不得不在很多地方将camelCase更改为snail_case.

Hey I have to change in a lot of places camelCase to snail_case.

我有以下示例:

billingAddress
paymentDetails

我试图在PhpStorm中使用查找并用正则表达式替换

I tried to use find and replace with regex in PhpStorm

在查找"输入字段中输入:

In 'find' input field I put in:

([A-Z])

在替换"输入字段中,我输入:

In 'replace' input field I put in:

_\L$1

我得到的结果:

billing_LAddress
payment_LDetails

为了获得以下结果,我需要更改什么:

What do I need to change in order to get following result:

billing_address
payment_details

推荐答案

首先使用 CTRL + R 打开查找和替换功能,然后选中相应的框Match CaseRegex(如果需要,还有In Selection):

First open Find and Replace functionality with CTRL + R and then check the boxes Match Case and Regex (and if necessary In Selection):

1.,如问题中所示,将 camelCase 替换为 snail_case :

1. To replace camelCase to snail_case as in in the question:

发现: ([A-Z])
替换: _\l$1

someThing -> some_thing

2.要将大写单词替换为小写单词,请使用\L

2. To replace UPPERCASE words to lowercase words use \L

发现: (\w*)
替换: \L$1

SOMETHING -> something

3.要将小写单词替换为大写单词,请使用\U

3. To replace lowercase words to UPPERCASE words use \U

发现: (\w*)
替换: \U$1

something -> SOMETHING

4.要用小写替换单词的第一个字符,请使用\l

4. To replace first character of words with lowercase use \l

发现: (\w*)
替换: \l$1

Something -> something

5.要用大写替换单词的第一个字符,请使用\u

5. To replace first character of words with UPPERCASE use \u

发现: (\w*)
替换: \u$1

something -> Something

通过添加一些适合您的特定情况的边界来获得最佳结果,例如单引号'或双引号"或换行符\n

You get best results by adding some additional boundaries that suit your specific case, for example single ' or double quotes " or line breaks \n

检查有关其他正则表达式语法的详细信息,有关 PHPStorm WebStorm .

Check for details on additional Regular Expression Syntax the documentation for PHPStorm or WebStorm.

这篇关于正则表达式在PhpStorm/Webstorm(Intellij-IDEA)中用小写字母替换大写的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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