Exact String Replace In Java

Exact String Replace Using Java Example explains how to replace exact string using java regular expression.

When you are in a situation where you just need to replace the exact string "Replace" from "Exact String Replace In Java"

For achieve this, we need to just put '\b' ("word boundary" in java regular expression) in between the words, that we are going to replace.

By using this regular expression allows you to perform a "whole words only" search using a regular expression and replace the specified string inside word boundary.

See the below regular expression example, which is showing how to replace an exact string in java.

Exact String Replace Example

public class ExactStringReplace {

// How to Replace String In Java

public static void main(String[] args) {
String text = "Replaced Exact String Replace In Java";
    text = text.replaceAll
("\\bReplace\\b", "Replaced");
Replaced Exact String Replaced In Java


2 Responses to "Exact String Replace In Java"
  1. Rose 2011-09-10 09:01:33.0
  1. admin 2011-09-11 09:01:33.0

Your email address will not be published. Required fields are marked *