You can use:
string result = string1.replaceFirst(Pattern.quote(string2), "");
Or you can completely avoid regular expressions:
int index = string1.indexOf(string2);
if (index == -1)
{
// Not found. What do you want to do?
}
else
{
String result = string1.substring(0, index) +
string1.substring(index + string2.length());
}
You can report the region here using indexand string2.length()very easily. Of course, if you want to be able to match regular expression patterns, you should use them.
EDIT: , "dear" "and_dear_Bob", "and__Bob" - , . , . . , , , , -, .
Edit:
: Hello c'Lint and dear Bob
Hello c'Lint .
:
string result = string1.replaceFirst(Pattern.quote(string2+" "), ""));
.