[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 3023
  • Last Modified:

How can I have Java's replaceAll function ignore case?

I'm working on a small project in Java and I can't seem to get the replaceAll function for strings to ignore the case. For example, I have
String str = "This is a Test string";
str = str.replaceAll("test", "#");

I've also tried
str = str.toLowerCase().replaceAll("test", "#");

The problem with that is it destroys the case. Is there anyway I can use replaceAll, and have it remove the specified string regardless of its case, without destroying the case of the whole sentence?
0
andy148
Asked:
andy148
1 Solution
 
0791882310Commented:
str = str.replaceAll("(?i)test", "#");
0
 
andy148Author Commented:
Seems to be working great. Thanks!
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now