Redian新闻
>
Java Regular Expression Question
avatar
Java Regular Expression Question# Java - 爪哇娇娃
T*e
1
In Perl, separating words with mixed caps in an identifier
like "RuntimeException" as "Runtime Exception" is fairly
easy. The regular expression for this can be:
$varName =~ s/([A-Z])/ \1/g;
or even better:
$varName =~ s/([^A-Z])([A-Z])/\1 \2/g;
$varName =~ s/([A-Z])([A-Z][a-z])/\1 \2/g;
Java's regular expression is pretty close to that of Perl
in term of searching for a pattern. However, can we do
similar replacement in Java without having to write a loop
to do searching and manua
avatar
m*t
2
String.replaceAll()?
avatar
T*e
3
I guess not if I understand it correctly.
String.replaceAll(String regex, String replacement)
The first parameter is for pattern searching, but the replacement
is simply a plain string and backreference does not work.

【在 m******t 的大作中提到】
: String.replaceAll()?
avatar
T*e
4
I guess not if I understand it correctly.
String.replaceAll(String regex, String replacement)
The first parameter is for pattern searching, but the replacement
is simply a plain string and backreference does not work.

【在 m******t 的大作中提到】
: String.replaceAll()?
相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。