-3

I have String as:

"change(String.valueOf(data.get("abc")),data.get("xyz"),data.get("def"))"

I want to change it to:

change(String.valueOf(data.get("abc")),String.valueOf(data.get("xyz")),String.valueOf(data.get("def")))".

How can I do the above operation using Java regex?

khelwood
  • 55,782
  • 14
  • 81
  • 108
  • 1
    Welcome to Stackoverflow. Add more details of the issue that you are facing.Share the relevant code snippets you have tried so far. – Nagama Inamdar Jul 24 '19 at 07:50

3 Answers3

0

Use : toString().replace("a", "o);

Example :

private String txt = "This is a text"

public static void main() String[arg] {

    String rplc = txt.replace("i", "o");
    System.out.print(rplc);

}

Output: Thos os a text

Michał Krzywański
  • 15,659
  • 4
  • 36
  • 63
Ipung
  • 1
  • 1
0
yourString.replaceAll("String.valueOf(data.get(").replaceAll("zzzzz").replaceAll("data.get(", "String.valueOf(data.get(").replaceAll("zzzzz", "String.valueOf(data.get(")

with 3 replaces

it is easer than using regex

0

According to your example, this simple replace should be enough:

result = source.replace(",data.get(\"");

For simple cases like this, you don't really need Regex (String.replaceAll(String regex, String replacement)) as using the regular replace is much faster (String.replace(CharSequence target, CharSequence replacement))

Mysterious Wolf
  • 373
  • 1
  • 5
  • 22