Java相当于Perl的///运算符? [英] Java equivalent of Perl's s/// operator?
问题描述
我有一些代码,我正在从Perl转换为Java。它大量使用正则表达式,包括 s ///
运算符。我已经使用Perl很长一段时间了,我仍然习惯于Java的做事方式。特别是,Strings似乎更难以使用。有没有人知道或者有一个完全实现 s ///
的Java函数?所以它可以处理这样的事情,例如:
I have some code that I'm converting from Perl to Java. It makes pretty heavy use of regular expressions, including the s///
operator. I've been using Perl for a long time and am still getting used to the Java way of doing things. In particular, Strings seem more difficult to work with. Does anyone know of or have a Java function that fully implements s///
? So that it could handle something like this, for example:
$newString =~ s/(\bi'?\b)/\U$1/g;
(也许不是一个很好的例子,但你明白了。)谢谢。
(Maybe not a great example, but you get the idea.) Thanks.
推荐答案
看看String的 replaceAll(...)方法。请注意,Java不支持 \ U
(大写)功能。
Have a look at String's replaceAll(...) method. Note that Java does not support the \U
(upper-case) feature.
这篇关于Java相当于Perl的///运算符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!