How to replace first occurrence of string in Java

java, replace, string

Solution

You can use `replaceFirst(String regex, String replacement)` method of String.

Problem

I want to replace first occurrence of String in the following. ``` String test = "see Comments, this is for some test, help us" ``` **If test contains the input as follows it should not replace - See Comments, (with space at the end) - See comments, - See Comments** I want to get the output as follows, ``` Output: this is for some test, help us ```

Original source

Related problems