[英]Regex replace uppercase with lowercase letters in PhpStorm/Webstorm (Intellij-IDEA)
Hey I have to change in a lot of places camelCase to snail_case.嘿,我必须在很多地方将camelCase 更改为snail_case。
I have following example:我有以下示例:
billingAddress
paymentDetails
I tried to use find and replace with regex in PhpStorm我尝试在 PhpStorm 中使用查找和替换正则表达式
In 'find' input field I put in:在“查找”输入字段中,我输入:
([A-Z])
In 'replace' input field I put in:在“替换”输入字段中,我输入:
_\L$1
Result I got:结果我得到:
billing_LAddress
payment_LDetails
What do I need to change in order to get following result:我需要更改什么才能获得以下结果:
billing_address
payment_details
First open Find and Replace functionality with CTRL
+ R
and then check the boxes Match Case
and Regex
(and if necessary In Selection
):首先使用
CTRL
+ R
打开查找和替换功能,然后选中Match Case
和Regex
框(如有必要, In Selection
):
1. To replace camelCase to snail_case as in in the question: 1.将camelCase替换为snail_case,如问题中所述:
find: ([AZ])
找到:
([AZ])
replace: _\\l$1
替换:
_\\l$1
someThing -> some_thing
2. To replace UPPERCASE words to lowercase words use \\L
2.要将大写单词替换为小写单词,请使用
\\L
find: (\\w*)
查找:
(\\w*)
replace: \\L$1
替换:
\\L$1
SOMETHING -> something
3. To replace lowercase words to UPPERCASE words use \\U
3.要将小写单词替换为大写单词,请使用
\\U
find: (\\w*)
查找:
(\\w*)
replace: \\U$1
替换:
\\U$1
something -> SOMETHING
4. To replace first character of words with lowercase use \\l
4.用小写替换单词的第一个字符,使用
\\l
find: (\\w*)
查找:
(\\w*)
replace: \\l$1
替换:
\\l$1
Something -> something
5. To replace first character of words with UPPERCASE use \\u\u003c/code>
5.用大写替换单词的第一个字符,使用
\\u\u003c/code>
find:
(\\w*)
查找:
(\\w*)
replace: \\u$1\u003c/code>
替换:
\\u$1\u003c/code>
something -> Something
Note: Add some extra boundaries
注意:添加一些额外的边界
You get best results by adding some additional boundaries that suit your specific case, for example single
'
or double quotes "
or line breaks \\n
通过添加一些适合您的特定情况的额外边界,您可以获得最佳结果,例如单
'
或双引号"
或换行符\\n
Regex Documentation
正则表达式文档
Check for details on additional Regular Expression Syntax the documentation for PHPStorm or WebStorm .
查看PHPStorm或WebStorm文档中有关其他正则表达式语法的详细信息。
根据PHPstorm 文档和我的测试,这现在有效:
_\l$1
What do I need to change in order to get following result:
我需要更改什么才能获得以下结果:
Nothing/Everything.没有/一切。 It's simply not supported ATM.
它根本不支持 ATM。
https://youtrack.jetbrains.com/issue/IDEA-70451 -- watch this ticket (star/vote/comment) to get notified on progress. https://youtrack.jetbrains.com/issue/IDEA-70451——观看这张票(明星/投票/评论)以获取进度通知。
UPDATE: This functionality is now implemented and available since PhpStorm v10.更新:从 PhpStorm v10 开始,此功能现已实现并可用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.