且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

用正则表达式更改字母的大小写

更新时间:2023-02-15 17:42:39

不幸的是,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).

演示屏幕: