0

I'm writing a program where there is a particular string in a line to be replaced

Below is my sample program.

public class MyFirstJavaProgram {

    public static void main(String []args) {
        String x="<link rel=\"stylesheet\" type=\"text/css\" href=\"abc.css\" />";
        System.out.println(x);

    }
} 

In the above program I want to replace abc.css with xyz.css. I'm aware of general String replacement function like String.replace(oldString, newString), But here the problem is that abc.css changes from file to file. I want to replace anything.css with xyz.css.

Here is a working Example Fiddle

please let me know how can I do this.

Thanks

user3872094
  • 3,083
  • 4
  • 29
  • 58

1 Answers1

1
 x=x.replaceAll("(.*)\"(.*)\\.css", "$1\"xyz\\.css");
Mayday
  • 3,966
  • 3
  • 19
  • 51