如何使用正则表达式替换附加到java字符串的开头?

gen*_*eek 0 java regex string

如何使用 java string replaceAll 或 replaceFirst 附加到开头?

String joe = "Joe";
String helloJoe = joe.replaceAll("\\^", "Hello");
Run Code Online (Sandbox Code Playgroud)

期望输出:“你好乔”

Avi*_*Raj 5

您不需要转义,^因为它^是正则表达式中与行首匹配的特殊元字符。

String helloJoe = whatever.replaceFirst("^", "Hello ");
Run Code Online (Sandbox Code Playgroud)