I have a string that contains String q = "What's the value of √32 and √83?";
, my problem is replacing √num
with sqrt(32)
and sqrt(83)
.
That means my string should output : -
What's the value of sqrt(32) and sqrt(83)
is it possible?
I have a string that contains String q = "What's the value of √32 and √83?";
, my problem is replacing √num
with sqrt(32)
and sqrt(83)
.
That means my string should output : -
What's the value of sqrt(32) and sqrt(83)
is it possible?
Use a regex replacement on the pattern √(\d+)\b
, and replace with sqrt(...)
:
String q = "What's the value of √32 and √83?";
String output = q.replaceAll("√(\\d+)\\b", "sqrt($1)");
System.out.println(output);
This prints:
What's the value of sqrt(32) and sqrt(83)?