本文介绍了用正则表达式更改字母的大小写的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Eclipse IDE中使用正则表达式。我试图将

I am using regular expressions in Eclipse IDE. I am trying to turn

other.test 转换为 other.getTest()

搜索: other。([az]] [[az] *)

替换: other.\U $ 1 $ 2()

结果: other.Utest()

我认为在组前面添加一个\U本来可以更改案子的,但对我不起作用。

I thought that adding a \U in front of the group was supposed to change the case, but its not working for me. any ideas?

推荐答案

不幸的是,Eclipse Find / Replace regex不支持像 \这样的大小写修改运算符U \u \L \ \l 。您可以使用jrahhali建议的较长解决方法,也可以使用Notepad ++:

Unfortunately, Eclipse Find/Replace regex does not support case modifying operators like \U, \u, \L and \l. You may either use a long workaround suggested by jrahhali, or use Notepad++:

搜索 other\。( [az] +)
替换 other.get\u $ 1\(\)

外植


  • other\。-匹配字符串 other。(注意点必须转义以匹配文字点)

  • ([az] +)-组1捕获1个或更多小写ASCII字母(仅选中 Match case 选项用 [az] + )匹配小写ASCII字母

  • other\. - matches a string other. (note the dot must be escaped to match a literal dot)
  • ([a-z]+) - Group 1 capturing 1 or more lowercase ASCII letters (check Match case option to only match lowercase ASCII letters with [a-z]+)

替换模式详细信息


  • other.get -文字 other.get

  • \u $ 1 -第1组的内容( $ 1 是对捕获的组1的反向引用,其第一个字符通过 \u 变为大写。运算符( \U 会把捕获组为大写)

  • \(\)-文字文本()(括号应在NPP Boost条件替换模式中转义)。

  • other.get - a literal text other.get
  • \u$1 - the contents of Group 1 (the $1 is a backreference to the captured group 1) and its first character is turned to upper case with \u operator (\U would turn the whole text of the capture group to upper case)
  • \(\) - a literal text () (the parentheses should be escaped in NPP Boost conditional replacement patterns).

演示屏幕:

这篇关于用正则表达式更改字母的大小写的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-12 22:04