-3

I have a String that looks like this:

downloadUrl = "https://example.com/uploads/images/quotes/hi/webp/dard-status-shayari-68854.webp";

It is basically a URL address. I'm looking to replace webp with jpg and .webp with .jpeg

I need output like the below:

https://example.com/uploads/images/quotes/hi/jpg/dard-status-shayari-68854.jpeg

I tried the solution given here but it's not working for me.

cconsta1
  • 737
  • 1
  • 6
  • 20
Manisha
  • 195
  • 1
  • 10

1 Answers1

1

Try something like this:

String result = source.replaceFirst("\\.webp$",".jpeg").replace("webp","jpg");

replaceFirst() will replace the extention, then replace() will replace the rest...

cconsta1
  • 737
  • 1
  • 6
  • 20
Usagi Miyamoto
  • 6,196
  • 1
  • 19
  • 33